AVAudioPlayer 当前时间问题
我正在尝试使用带有滑块的 AVAudioPlayer
来寻找轨道(没什么复杂的)。
但我有一个奇怪的行为......对于 currentTime
的某个值(0 和 trackDuration 之间),播放器停止播放曲目,并进入 audioPlayerDidFinishPlaying:successively:
成功到NO。 它没有进入 audioPlayerDecodeErrorDidOccur:error:
这就像它无法读取我给它的时间。
例如,曲目的持续时间为:295.784424 秒 我将 currentTime
设置为 55.0s(即:54.963878 或 54.963900 或 54.987755 等...当打印为 %f 时)。 当 currentTime
为 54.987755 时,总会发生“崩溃”...我真的不明白为什么...
所以如果你有任何想法...^^
I'm trying to use the AVAudioPlayer
with a slider in order to seek into a track (nothing complicated).
But I have a weird behavior... for some value of currentTime
(between 0 and trackDuration), the player stop playing the track, and goes into audioPlayerDidFinishPlaying:successfully:
with successfully to NO. And it did not go into audioPlayerDecodeErrorDidOccur:error:
It's like it can't read the time I'm giving to it.
For exemple the duration of the track is: 295.784424 seconds
I set the currentTime
to 55.0s (ie: 54.963878 or 54.963900 or 54.987755, etc... when printed as %f).
The "crashes" always happen when the currentTime
is 54.987755... and I really don't understand why...
So if you have any idea... ^^
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我还努力让音频跳过与“AVAudioPlayer setCurrentTime:”正常工作
经过大量实验后,我发现了一个在模拟器和设备上可靠工作的序列:(在 OS3.1+ 上测试)
I also struggled to get audio skipping working properly with 'AVAudioPlayer setCurrentTime:`
After alot of experimentation i've found a sequence that works reliably on the simulator and the device: (tested on OS3.1+)
我已经尝试使用设备,这是一个仅在模拟器上出现的问题。
我的所有文件都可以在设备上正常播放,并且我可以在其中轻松查找。
我尝试过 mp3、aac 和 wav。
I've tried with a device, and this is an issue that occurs only with the simulator.
All my files are well played on the device, and I can seek easily inside them.
I've tried mp3, aac and wav.
由于某种原因,当我收到此错误时,标志仍设置为 YES。 我设法通过检查 currentTime 与持续时间并在 currentTime 不是 0.0(声音结束)时立即重新启动播放器来找到解决方法。 我的所有测试都是在模拟器上完成的,因为我还没有在手机上进行测试的许可证。 希望这可以帮助。 请参阅一些怪癖的编辑。
编辑:不幸的是,当寻找声音的开头或结尾(或两者的很小增量)时,我仍然发现错误。 我发现,如果您创建处理这两个实例的特殊情况,那么您通常会受到保护。 您应该停止播放器,将 currentTime 设置为 0.0,然后如果要查找开头则再次启动播放器,或者如果您要查找结尾(如果您实现了它),则手动调用完成委托。
如果我找到更好的解决方案或在实际设备上运行此程序获得更多反馈,我将进行更新。
For some reason when I get this error, flag is still set to YES. I've managed to find a workaround by checking currentTime vs. duration and restarting the player immediately if the currentTime isn't 0.0 (the end of the sound). All of my testing is done on the simulator as I do not have a license to test on my phone yet. Hope this helps. See edits for a couple quirks.
EDIT: Unfortunately, I have still found errors when seeking to the very beginning or very end of a sound (or in a very small increment of either). I've found that if you create special cases that handle those two instances you are generally covered. You should stop the player, set the currentTime to 0.0 and then either start the player again if seeking to the beginning or manually calling the finish delegate if you are seeking to the end (if you implemented it).
If I find a better solution or get more feedback running this on an actual device I'll update.