无法在AVAudioplayer中实现前向动作 [英] Unable to Implement Forward Action in AVAudioplayer
问题描述
我正在使用AVAudioplayer播放一些音频文件。我有一些控制,如前进和后退。
I am using AVAudioplayer to play some audio files. I have some controls like forward and rewind.
倒带工作正常,但前进不是。
Rewind is working properly but forward is not.
- (void)rewind
{
AVAudioPlayer *player = _rewTimer.userInfo;
player.currentTime-= SKIP_TIME;
[_rewTimer invalidate];
_rewTimer=nil;
[self updateCurrentTime];
}
- (void)ffwd
{
AVAudioPlayer *player = _ffwTimer.userInfo;
player.currentTime-= SKIP_TIME;
[player setCurrentTime:cTime];
[_ffwTimer invalidate];
_ffwTimer=nil;
[self updateCurrentTime];
}
只要我点击前进按钮,音频文件就会开始播放开始。
As soon as I click on forward button, the audio file just begins playing from the start.
我已经关注了Apple的示例应用程序avTouch。
I have followed the sample app avTouch from Apple.
推荐答案
你可能已经完成了
AVAudioPlayer *播放器的属性声明; h文件中的
也合成了它。
现在转发,只需要,
you might have done the property declaration of AVAudioPlayer *player; in the h file and also synthesised it. Now for forward, just do,
- (void)ffwd
{
NSTimeInterval *time = [player currentTime];
time+=SKIP_TIME;
[player setCurrentTime:time];
}
做同样的倒带+
OR
- (void)ffwd{
NSTimeInterval time = avPlayer.currentTime;
time+=SKIP_TIME;
if (time > avPLayer.duration)
{
//nothing to do
}
else
[player setCurrentTime:time];
}
这个似乎是更好的方式,也适用于倒带比较0而不是持续时间
this one seems the better way, also for rewind compare to 0 instead of duration
这篇关于无法在AVAudioplayer中实现前向动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!