Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift: How to access player object of full screen HTML video?

Tags:

ios

swift

I want to be able to hold a reference to the AVPlayer instance that takes over the screen when playing HTML videos full screen from embedded browsers. My first approach was this:

extension AVPlayerViewController {

    override public func viewDidAppear(animated: Bool) {
      super.viewDidAppear(animated)

      print("herezzzzzzzzzzzzzzzzzzzzzzzzzzz") // prints correctly
      print(self.player) // prints nil
    }
}

However it always returns nil. So I'm trying a different approach. I want to override either the initializer or play method of AVPlayer but I can't seem to do it without getting objective-c selector conflicts.

import AVKit
import MediaPlayer

extension AVPlayer {
  override func play() { // this doesn't work. just an example of what i want
    super.play()

    print("do stuff here")
  }
}

Is there a way to override one of AVPlayer's instance methods so I can store a reference to self? Or is it not even an AVPlayer?

like image 827
bigpotato Avatar asked Sep 01 '16 23:09

bigpotato


1 Answers

"The most important classes used for playing video content within that UIWebView are called MPAVController and UIMoviePlayerController". So you can't get the instance of AVPlayer.

Please check this question: How to receive NSNotifications from UIWebView embedded YouTube video playback for more detail.

like image 139
Quang Hà Avatar answered Nov 02 '22 18:11

Quang Hà