iOS:如何在特定时间内发生特定操作?
在我的应用程序中,我使用 AVAudioPlayer 对象来保存 mp3 文件。我有好几次希望在播放文件时降低文件的音量。
我明白我应该做的一些事情,但我不明白如何定义持续时间以及如何命令某些事情仅在该持续时间内发生。
我正在寻找这样的东西:
AVAudioPlayer * aud1 = [I have a method to get the file];
AVAudioPlayer * aud2 = [I have a method to get the file];
NSTimeInterval * aud1_ti = aud1.duration //I haven't tried this yet - is this the right way to get the mp3 play duration?
[aud1 play];
[aud2 play];
while (aud1_ti)
aud2.volume = 0.5;
aud2.volume = 1.0
用语言来说 - 我希望在播放 aud1 时,aud2 的音量减半;一旦文件到达末尾,aud2 音量将恢复到最大音量。我无法从文档中理解如何做到这一点。
有人可以帮忙吗?
In my app I'm using AVAudioPlayer objects to hold the mp3 files. I have several occasions where I wish to lower the sound level of the files while they are being played.
I understand some of what I'm supposed to be doing, but I don't understand how I define the duration and how do I command that something will happen only for that duration.
I'm looking for something like this:
AVAudioPlayer * aud1 = [I have a method to get the file];
AVAudioPlayer * aud2 = [I have a method to get the file];
NSTimeInterval * aud1_ti = aud1.duration //I haven't tried this yet - is this the right way to get the mp3 play duration?
[aud1 play];
[aud2 play];
while (aud1_ti)
aud2.volume = 0.5;
aud2.volume = 1.0
To say it in words - I wish that while aud1 is playing, aud2 volume will be reduced in half; and once the file had reached its end the aud2 volume will get back to its full level. I couldn't understand from the documentation how to do that.
Can anyone assist?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想要做的不是让 AVAudioPlayer 的代表响应 – audioPlayerDidFinishPlaying:successively: 并重置当时的音量。在非常非常基本的层面上,您将得到如下内容:
注意,上面的代码显然不完整,但应该为您指明正确的方向。
Rather than basing this off of the duration what you probably want to do is have the delegate of your AVAudioPlayer respond to – audioPlayerDidFinishPlaying:successfully: and reset the volume at that time. On a very, very basic level you will have something like this:
Note, the code above is obviously incomplete but should point you in the right direction.