2013-10-31 48 views

回答

1

您可以簡單地使用AVAudioPlayer

- (void) playPauseButtonSelector: (UIButton*) sender 
{ 
if (!_isPlaying) 
{ 
    //play song 
    _timer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(updateTime:) userInfo:nil repeats:YES]; 

    [_audioPlayer setCurrentTime:_startingTime]; 

    [_audioPlayer play]; 

    _isPlaying = YES; 
} 
else 
{ 
    //pause action 
    [_audioPlayer pause]; 
    [_timer invalidate]; 
    _timer = nil; 
    _isPlaying = NO; 
} 
} 

在功能錄入,與終點比較audioPlayer的currentTime的停止播放

- (void) updateTime: (NSTimer*) time 
{ 

if (_audioPlayer.currentTime >= _endingTime) 
{ 
    //pause 
    [self playPauseButtonSelector:nil]; 
} 

} 
+0

謝謝您的回答。這是我需要的東西。 –

相關問題