Friday, 29 March 2019

How to detect AVplayer and get url of current video from WKWebView?

I'm using below code for get url from UIWebView it is working fine but, this same code using for WKWebView it's not working anymore. can anyone help me ?

my code is :

 NotificationCenter.default.addObserver(self, selector: #selector(self.playerItemBecameCurrent(_:)), name: NSNotification.Name("AVPlayerItemBecameCurrentNotification"), object: nil)

 @objc func playerItemBecameCurrent(_ sender : NSNotification){
    let playerItem: AVPlayerItem? = sender.object as? AVPlayerItem
    if playerItem == nil {
        print("player item nil")
        return
    }
    // Break down the AVPlayerItem to get to the path
    let asset = playerItem?.asset as? AVURLAsset
    let url: URL? = asset?.url
    let path = url?.absoluteString

    print(path!,"video url")
}

so please help me how to get this. Thanks.



from How to detect AVplayer and get url of current video from WKWebView?

No comments:

Post a Comment