iosobjective-cavplayeravplayeritem

Stop AVPlayer and restart MP3 file again


I want to start, pause and stop (same as restart) my mp3 File and I'm using AVPlayer. I get the files from a server.

To start the song I do:

[self.player start];

To pause I do:

[self.player pause];

but when I want to stop the song and reload it, so that the song starts from the beginning when the User clicks on the "start button" next time, I have no idea what to do.

I tried something like this:

[self.player pause];
self.player = nil;

But then the player is nil of course and I can't restart the file again without a new initialization. Any ideas how to stop it?


Solution

  • Stop the video using [player pause]

    Then use this code when you start the video.

    [player seekToTime:kCMTimeZero];
    [player play];
    

    I like this better than the comment that solved the OP it b/c it eliminates a warning and uses a constant.