如何使用AVAudioPlayer从时间t1到t2在Xcode中播放mp3文件 [英] How to play an mp3 file in Xcode from time t1 to t2 with AVAudioPlayer

查看:108
本文介绍了如何使用AVAudioPlayer从时间t1到t2在Xcode中播放mp3文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在t1到t2的时间之间,是否有更优雅的方法可以使用AVAudioPlayer Class播放mp3文件而不使用NSTimers?

I wonder if there is a more elegant way to play a mp3 file with AVAudioPlayer Class, from t1 to t2 time without using NSTimers?

推荐答案

AVAudioPlayer 具有方法playAtTime:可以处理 t1 ,但是没有简单的方法可以在特定时间( t2 )停止播放.

AVAudioPlayer has a method playAtTime: which takes care of t1, however there's no easy way to stop playing at a specific time (t2).

iOS8 起, AVFoundation 具有新的api,例如 AVAudioEngine AVAudioPlayerNode .您可能会发现实现 AVAudioPlayerNode 更加适合您的要求,因为它有一个名为

As of iOS8 AVFoundation has new api's such as AVAudioEngine and AVAudioPlayerNode. You may find implementing AVAudioPlayerNode instead is more suited for your requirements as it has a method named

- scheduleSegment:startingFrame:frameCount:atTime:completionHandler:

用于播放音频文件的一部分.

which is for playing a segment of an audio file.

这篇关于如何使用AVAudioPlayer从时间t1到t2在Xcode中播放mp3文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆