Search code examples
iosvideo-streamingavplayerhttp-live-streaming

how to set a view layer to white when AVplayer is paused?


I am playing hls videos using AVPlayer inside a view. Now when stop the playback the video stops but the last frame, keeps showing in the view. Now i want to clear that frame and and make that view white, how do i do it? i have tried setting the view background to white but nothing happens.


Solution

  • Setting a background doesn't have any effect because AVPlayer renders its content on top of the background, completely overlaying it. You could just hide AVPlayer's view completely or set it's player property to nil when your AVPlayer finishes playing.

        [[NSNotificationCenter defaultCenter] addObserverForName:AVPlayerItemDidPlayToEndTimeNotification
                                                      object:player
                                                       queue:[NSOperationQueue mainQueue]
                                                  usingBlock:^(NSNotification *note) {
                                                      view.player = nil;
                                                      //or view.hidden = YES;
                                                  }];