AVPlayer full screen output

I use AVPlayerto display some video streams (with a fixed length). The problem is when the content is completed, the player (if it was installed in full screen mode by the user) still remains in full screen mode.

Any way to get a player to minimize state immediately after playing content?

+1
source share
2 answers

To add to the long answer,

You can disable the video player with rejectViewControllerAnimated function in itemDidFinishPlaying function. You should also remember to delete the observer that you created after you are done.

-(void)startPlaybackForItemWithURL:(NSURL*)url {

     // First create an AVPlayerItem
     AVPlayerItem* playerItem = [AVPlayerItem playerItemWithURL:url];

     // Subscribe to the AVPlayerItem DidPlayToEndTime notification.


    [[NSNotificationCenter defaultCenter] 
      addObserver:self 
        selector:@selector(itemDidFinishPlaying:) 
        name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem];

    // Begin playback
    [player play]
} 

-(void)itemDidFinishPlaying:(NSNotification *) notification {
     // Will be called when AVPlayer finishes playing playerItem
     [self dismissViewControllerAnimated:YES completion:Nil]
     [[NSNotificationCenter defaultCenter] 
        removeObserver:self 
        name:AVPlayerItemDidPlayToEndTimeNotification 
        object:Nil];

}
+1

/ / View

-(void)startPlaybackForItemWithURL:(NSURL*)url {

 // First create an AVPlayerItem
 AVPlayerItem* playerItem = [AVPlayerItem playerItemWithURL:url];

 // Subscribe to the AVPlayerItem DidPlayToEndTime notification.
 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidFinishPlaying:) name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem];

// Begin playback
[player play]

} 

-(void)itemDidFinishPlaying:(NSNotification *) notification {
 // Will be called when AVPlayer finishes playing playerItem

}
0

Source: https://habr.com/ru/post/1659720/


All Articles