Search code examples
iosswiftaudioavplayeravplayerviewcontroller

Set background image of AVPlayerViewController


i'm using AVPlayerViewController for playing audios. Reason for using it is that it provides and handles basic controls i.e. play/pause/slider/volume.

Now, i need to set background image of this view. Image will be fetched from some network location. i debugged AVPlayerViewController's view hierarchy. There's an image view. I'm not sure how to access that or even if it's possible

I don't want to use AVPlayer or AVAudio player as in that case i'll have to handle all the controls.How can i do that?


Solution

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

    Add UIImageView as contentOverlayView.Add button etc also if you want custom design for them too.

    controller.contentOverlayView.addsubview(myImageView)
    

    To cahnge color etc:

    controller.contentOverlayView.backgroundColor = UIColor(red: 178/255, green: 178/255, blue: 122/255, alpha: 1)
    

    for more check following link

    Change AVPlayerViewController background to album artwork objective-c iOS