我也掙扎着跳音同「AVAudioPlayer setCurrentTime正常工作:`
實驗後,很多我發現,在模擬器和設備工作可靠的順序:(上OS3.1 +測試)
// Skips to an audio position (in seconds) of the current file on the [AVAudioPlayer* audioPlayer] class instance
// This works correctly for a playing and paused audioPlayer
//
- (void) skipToSeconds:(float)position
{
@synchronized(self)
{
// Negative values skip to start of file
if (position<0.0f)
position = 0.0f;
// Rounds down to remove sub-second precision
position = (int)position;
// Prevent skipping past end of file
if (position>=(int)audioPlayer.duration)
{
NSLog(@"Audio: IGNORING skip to <%.02f> (past EOF) of <%.02f> seconds", position, audioPlayer.duration);
return;
}
// See if playback is active prior to skipping
BOOL skipWhilePlaying = audioPlayer.playing;
// Perform skip
NSLog(@"Audio: skip to <%.02f> of <%.02f> seconds", position, audioPlayer.duration);
// NOTE: This stop,set,prepare,(play) sequence produces reliable results on the simulator and device.
[audioPlayer stop];
[audioPlayer setCurrentTime:position];
[audioPlayer prepareToPlay];
// Resume playback if it was active prior to skipping
if (skipWhilePlaying)
[audioPlayer play];
}
}
結果只是暫停,更改.currentTime然後播放在所有情況下都不起作用。使用停止,而不是像這裏建議的幫助我。 – Jonny 2016-02-16 01:56:17