<tfoot id='FZlAY'></tfoot>
    <i id='FZlAY'><tr id='FZlAY'><dt id='FZlAY'><q id='FZlAY'><span id='FZlAY'><b id='FZlAY'><form id='FZlAY'><ins id='FZlAY'></ins><ul id='FZlAY'></ul><sub id='FZlAY'></sub></form><legend id='FZlAY'></legend><bdo id='FZlAY'><pre id='FZlAY'><center id='FZlAY'></center></pre></bdo></b><th id='FZlAY'></th></span></q></dt></tr></i><div id='FZlAY'><tfoot id='FZlAY'></tfoot><dl id='FZlAY'><fieldset id='FZlAY'></fieldset></dl></div>

    1. <small id='FZlAY'></small><noframes id='FZlAY'>

        <bdo id='FZlAY'></bdo><ul id='FZlAY'></ul>

    2. <legend id='FZlAY'><style id='FZlAY'><dir id='FZlAY'><q id='FZlAY'></q></dir></style></legend>

        如何检测音效何时播放完毕?

        时间:2024-08-12
      1. <i id='x6KFl'><tr id='x6KFl'><dt id='x6KFl'><q id='x6KFl'><span id='x6KFl'><b id='x6KFl'><form id='x6KFl'><ins id='x6KFl'></ins><ul id='x6KFl'></ul><sub id='x6KFl'></sub></form><legend id='x6KFl'></legend><bdo id='x6KFl'><pre id='x6KFl'><center id='x6KFl'></center></pre></bdo></b><th id='x6KFl'></th></span></q></dt></tr></i><div id='x6KFl'><tfoot id='x6KFl'></tfoot><dl id='x6KFl'><fieldset id='x6KFl'></fieldset></dl></div>

        <tfoot id='x6KFl'></tfoot>

              <tbody id='x6KFl'></tbody>

                <small id='x6KFl'></small><noframes id='x6KFl'>

                <legend id='x6KFl'><style id='x6KFl'><dir id='x6KFl'><q id='x6KFl'></q></dir></style></legend>
                  <bdo id='x6KFl'></bdo><ul id='x6KFl'></ul>
                  本文介绍了如何检测音效何时播放完毕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 SimpleAudioEngine,并尝试在继续之前检测音效是否播放完毕.

                  I'm using SimpleAudioEngine and I'm trying to detect if a sound effect is finish playing before continuing.

                  我正在寻找任何方法,但我尝试实施的方法不起作用!

                  I'm looking for any method, but the one I'm trying to implement doesn't work!

                  CDSoundEngine *engine = [CDAudioManager sharedManager].soundEngine;    
                  ALuint soundId = [[SimpleAudioEngine sharedEngine] playEffect:soundId];
                  
                  float seconds = [engine bufferDurationInSeconds:soundId];
                  

                  每次我使用 bufferDurationInSeconds 时,它都会返回一个浮点值 -1 到变量秒.我检查了实现,当 ID 无效时它返回 -1,但我 100% ID 是有效的!

                  Every time I use bufferDurationInSeconds, it returns a float value of -1 to variable seconds. I checked the implementation, and it returns a -1 when the id is not valid, but I'm 100% the ID is valid!

                  谁能帮我解决这个问题,或者建议我另一种方法来检测声音效果的结束?

                  Can anyone help me on this problem, or suggest me another way to detect the end of an sound effect?

                  推荐答案

                  Violà!获取 CDSoundSource,然后从中获取 soundId.

                  Violà! Getting CDSoundSource, and then the soundId from that works.

                  (第二行是可选的,它只是播放声音).

                  (The second line is optional, it just plays the sound).

                  CDSoundEngine *engine = [CDAudioManager sharedManager].soundEngine;
                  [[SimpleAudioEngine sharedEngine] playEffect:@"soundeffect.m4a"];
                  CDSoundSource *aSound =[[SimpleAudioEngine sharedEngine] soundSourceForFile:@"soundeffect.m4a"];
                  float seconds = [engine bufferDurationInSeconds:aSound.soundId];
                  

                  还要在播放完毕后立即运行一个方法,我会使用一个使用秒结果的 NSTimer.

                  Also to run a method right when it finishes playing I would use an NSTimer that uses the seconds result.

                  [NSTimer scheduledTimerWithTimeInterval:seconds target:self selector:@selector(aMethod) userInfo:nil repeats:NO];
                  

                  然后最后的方法实现了一些东西.

                  And then the final method implements something.

                  -(void)aMethod 
                  {
                  NSLog(@"finished playing");
                  }
                  

                  虽然这不会影响 -1 结果,但我必须指出,soundId 变量在您的代码中以两种不同的类型出现两次,在同一行中,这会导致问题.不过不用担心,我已经成功测试了上面的方法.

                  Although, this doesn't effect the -1 result, I have to point out that the soundId variable appears twice as two different kinds in your code, in the same line, which will cause problems. No worries though, I have tested my method above with success.

                  ALuint **soundId** = [[SimpleAudioEngine sharedEngine] playEffect:**soundId**];
                  

                  这篇关于如何检测音效何时播放完毕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何实现高清“Retina Display"Cocos2D 中的图形 下一篇:Cocos2d 游戏中的碰撞检测?

                  相关文章

                  <legend id='k8HiL'><style id='k8HiL'><dir id='k8HiL'><q id='k8HiL'></q></dir></style></legend>
                      <bdo id='k8HiL'></bdo><ul id='k8HiL'></ul>
                  1. <tfoot id='k8HiL'></tfoot>
                    <i id='k8HiL'><tr id='k8HiL'><dt id='k8HiL'><q id='k8HiL'><span id='k8HiL'><b id='k8HiL'><form id='k8HiL'><ins id='k8HiL'></ins><ul id='k8HiL'></ul><sub id='k8HiL'></sub></form><legend id='k8HiL'></legend><bdo id='k8HiL'><pre id='k8HiL'><center id='k8HiL'></center></pre></bdo></b><th id='k8HiL'></th></span></q></dt></tr></i><div id='k8HiL'><tfoot id='k8HiL'></tfoot><dl id='k8HiL'><fieldset id='k8HiL'></fieldset></dl></div>

                    <small id='k8HiL'></small><noframes id='k8HiL'>