[英]fast forwarding a song using AVAudioPlayer
I am creating an audio player application, i need to enable the user to fast forward and backward a song by holding a button(seperately for each).我正在创建一个音频播放器应用程序,我需要让用户通过按住一个按钮(分别为每个按钮)来快进和快退歌曲。 I've done for playing, stopping, skip to next and previous song.
我已经完成了播放、停止、跳到下一首和上一首歌曲。 But i got stuck with this section.
但我被这部分卡住了。 I dont know the method to implement this.
我不知道实现这个的方法。 pls help.
请帮忙。
Use the currentTime
and duration
properties.使用
currentTime
和duration
属性。
ie to skip forward即向前跳过
NSTimeInterval time = avPlayer.currentTime;
time += 5.0; // forward 5 secs
if (time > avPLayer.duration)
{
// stop, track skip or whatever you want
}
else
avPLayer.currentTime = time;
Similar for going backwards, only compare currentTime
against 0
, instead of duration
类似于倒退,只将
currentTime
与0
进行比较,而不是duration
In swift 4在迅速 4
for forward为前进
var timeForward = audioPlayer.currentTime
timeForward += 10.0 // forward 10 secs
if (timeForward > audioPlayer.duration) {
audioPlayer.currentTime = timeForward
} else {
audioPlayer.currentTime = audioPlayer.duration
}
for backward为落后
var timeBack = audioPlayer.currentTime
timeBack -= 10.0 //backward 10 secs
if (timeBack > 0) {
audioPlayer.currentTime = timeBack
} else {
audioPlayer.currentTime = 0
}
Hope this will help.希望这会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.