How to get the url of currently playing video in UIWebview

Is there a way to get a link to the current video. I download m.youtube.com . For some videos, he doesn't even introduce delegates. I also tried using NStimer. But for some videos this is not a URL click

+4
source share
2 answers

There is a hacker way to do this by listening to the notification AVPlayerItemBecameCurrentNotification. This notification is triggered when the UIWebView shows the media player and it sends AVPlayerItema notification as an object.

For instance:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(playerItemBecameCurrent:)
                                             name:@"AVPlayerItemBecameCurrentNotification"
                                           object:nil];


-(void)playerItemBecameCurrent:(NSNotification*)notification {
    AVPlayerItem *playerItem = [notification object];
    if(playerItem == nil) return;
    // Break down the AVPlayerItem to get to the path
    AVURLAsset *asset = (AVURLAsset*)[playerItem asset];
    NSURL *url = [asset URL];
    NSString *path = [url absoluteString];
}

( ). , , YouTube - , Apple WILL , YouTube AT ALL, YouTube.

+11

:

// NSNotificationcenter

override func viewDidAppear(_ animated: Bool) {
    NotificationCenter.default.addObserver(self, selector:#selector(playerItemBecameCurrent), name:NSNotification.Name(rawValue: "AVPlayerItemBecameCurrentNotification"), object:nil)
}

//

@objc func playerItemBecameCurrent(notification:NSNotification){
    let playerItem:AVPlayerItem = notification.object as! AVPlayerItem
    let asset:AVURLAsset=playerItem.asset as! AVURLAsset
    let url = asset.url
    let path = url.absoluteString
    print(path)

}
0

All Articles