如何播放从 45 秒标记到 51 秒标记的文件?

How can I play a file from 45 sec mark to the 51 sec mark?

给定一个 m4a 文件...我如何播放从 45 秒标记到 51 秒标记的文件?

我只想播放该文件的 6 秒,而不是等待 45 秒才能听到它播放。谢谢

这是我播放整个文件的方式:

NSURL *soundFileURL = [[NSBundle mainBundle] URLForResource:@"abc" withExtension:@"m4a"];

player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
player.numberOfLoops = 1; 

[player play];

来自文档:

- (BOOL)playAtTime:(NSTimeInterval)time

Plays a sound asynchronously, starting at a specified point in the audio output device’s timeline.

例如,要在调用此方法后三秒后开始播放,请使用如下代码:

NSTimeInterval playbackDelay = 3.0;              
[myAudioPlayer playAtTime: myAudioPlayer.deviceCurrentTime + playbackDelay];

6 秒后,您可以停止音频播放器。您可以将音频播放器的当前时间与 51 秒进行比较,或者您可以拥有自己的计时器。

if(myAudioPlayer.currentTime >= 51{
    [myAudioPlayer stop];
 }