Change AVPlayerViewController background to album

2019-06-24 04:47发布

问题:

Is it possible to change the background of an AVPlayerViewController instance when playing audio ?

When I lock my device, I can see the music controls with album artwork correctly shown but when the AVPlayerViewController is shown in my app, I can only see the controls with a background representing QuickTime currently playing.

Here is how I call it :

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];


        NSURL *url=[NSURL fileURLWithPath:clickedPath];
        AVPlayer *player = [AVPlayer playerWithURL:url];


        AVPlayerViewController *controller = [[AVPlayerViewController alloc] init];
        [self presentViewController:controller animated:YES completion:nil];
        controller.player = player;
        [player play];

回答1:

Yes you can customize AVPlayerViewController by customizing it's contentOverlayView.

You can customise contentOverlayView.

see the Apple documentation, it states

You can use the content overlay view to add additional custom views between the video content and the playback controls.

for example,

  AVPlayerViewController *controller =  [[AVPlayerViewController alloc] init];

[controller.contentOverlayView setBackgroundColor:[UIColor greenColor]];

like wise you can add other controls like button,label etc to that contentOverlayView.

Hope this will help :)