Stop AVPlayer on iOS

I use AVPlayer to play live stream from the Internet. AVPlayer can be paused, but when it resumes, it starts from the moment it is suspended, like TiVO. AVPlayer does not have a stop method.

How to make it continue broadcasting now (as if you turned the car radio off and on again)?

+6
iphone cocoa-touch ios4 ipad avplayer
source share
4 answers

-(void)seekToTime:(CMTime)time

use this method to go to the beginning of the file

+1
source share

To stop AVPlayer :

 [player replaceCurrentItemWithPlayerItem:nil]; 

This will free up all the memory and processor resources that it uses and the associated assets. Just like that.

+1
source share

SeekToTime does not stop the sound, so as soon as you reach the end, if you just call seekToTime, it just starts playing again like a loop. You can use the callback version below to pause video / audio as soon as the search is complete so that it resets and stops at the same time.

 [_player seekToTime:CMTimeMake(0, 1) completionHandler:^(BOOL finished) { [_player pause]; }]; 
-one
source share
  [player pause]; [item_ removeObserver:self forKeyPath:@"status" context:nil]; [item_ removeObserver:self forKeyPath:@"playbackBufferEmpty" context:nil]; [item_ removeObserver:self forKeyPath:@"playbackLikelyToKeepUp" context:nil]; [item_ removeObserver:self forKeyPath:@"timedMetadata" context:nil]; player=nil; 
-one
source share

All Articles