1

I am wondeing: Is there any method to skip to a specific time or skip a specific lapse with IOS Mediaplayer? I cannot find anything similar in the docs.

There is a property myMediaPlyer.currentPlaybackTime

and there is the method myMediaPlayer.beginSeekingForward()

but the method just plays the music in fast mode, which is not what I want. Just wondering if someone knows how to handle this

Jorge Zingg
  • 68
  • 1
  • 7

1 Answers1

0

Yes, you can seek to any time forward or backward within the media player item duration. if you are using AVPlayer, you can seek using this method:

func seek(to seconds: Int) {
    let targetTime:CMTime = CMTimeMake(value: Int64(seconds), timescale: 1)
    player.seek(to: targetTime)
}

And if you are using AVAudioPlayer, you can seek using this method:

func seek(to seconds: Int) {
    player.currentTime = TimeInterval(seconds)
}
  • Thanks for the response! Unfortunately, I am using MPMusicPlayerController.applicationQueuePlayer, to play music from the device's music library, and MPMusicPlayerController has no week method... I wanted to keep the music in the library and just play it in the app, but I guess i'll need to change the approach. – Jorge Zingg Oct 21 '18 at 11:34