ios – 在UIWebView中从AVPlayer获取视频URL

前端之家收集整理的这篇文章主要介绍了ios – 在UIWebView中从AVPlayer获取视频URL前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图通过这种方法检测从UIWebView播放的当前视频的URL:
func webView(_ webView: UIWebView,shouldStartLoadWith request: URLRequest,navigationType: UIWebViewNavigationType) -> Bool
    {

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

        //urlTextField.text = webView.request?.url?.absoluteString

        return true
    }



  func playerItemBecameCurrent(notification:Notification)  {

        let playerItem: AVPlayerItem? = notification.object as? AVPlayerItem
        if playerItem == nil {
            return
        }
        // Break down the AVPlayerItem to get to the path
        let asset: AVURLAsset? = (playerItem?.asset as? AVURLAsset)
        let url: URL? = asset?.url
        let path: String? = url?.absoluteString
        print(path!)

    }

代码有效,但视频网址不包含任何视频文件扩展名:
例如,这里是YouTube和Vimeo视频ULR:

https://r5---sn-ab5l6nzr.googlevideo.com/videoplayback?mime=video%2Fmp4&requiressl=yes&clen=27257208&mn=sn-ab5l6nzr&mm=31&mv=m&mt=1499534990&key=yt6&ms=au&source=youtube&ip=107.182.226.163&sparams=clen%2Cdur%2Cei%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cexpire&initcwndbps=3565000&id=o-ACG22m-TtwyC8tSG_AHUJk3qOPvhUm1X_-qRjy07pjIx&ei=-hZhWZXcJ_aV8gS2tbCQDg&lmt=1497638262979584&ratebypass=yes&gir=yes&pl=25&expire=1499556698&dur=316.093&signature=94C8ED3E4AF64A7AC9F1B7E226454823B236CA55.C18F5F5D9D314B73EDD01DFC4EA3CEA1621AC6C7&ipbits=0&itag=18&cpn=Wb3RPNfJRcFx5P-x&c=MWEB&cver=1.20170706&ptk=TiTV2010%2Buser&oid=1nI2Jk44kRu4HLE6kGDUrA&ptchn=E2VhHmwp3Y_wZvgz_LJvfg&pltype=content

和Vimeo:

https://36skyfiregce-vimeo.akamaized.net/exp=1499539063~acl=%2F222646835%2F%2A~hmac=dc3caeb64501f537e2795ee8e121aed75a7eed9ba4e1b921fe92c757fe06b314/222646835/video/778109097,778109103,778109102,778109101/master.m3u8?f=dash

解决方法

首先,我想告诉你,你的编码工作正常.

镜像服务器

这是因为在上传,下载和流媒体处理过程中谷歌正在使用域名为googlevideo.com的镜像服务器.

您在流式传输状态下访问链接视频.您将只获得该镜像链接.
Youtube视频位于此镜像服务器中.

与Vimeo使用镜像服务器akamaized.net相同

请参阅SO POST以获得澄清

从镜像URL解码视频链接

所以在这种情况下,我们需要拥有的是youtube中视频的唯一ID,并且可以通过附加网址https://www.youtube.com/watch?v=id_here来访问

对于解码此镜像URL中的唯一ID是不可能的,如SO Answer所示

他们添加了这个镜像服务器概念,是为了获得一些安全性.

根据youtube T& C ..第5B节 – http://www.youtube.com/static?template=terms

Downloading YouTube content is not in compliance with the YouTube
Tearms of Service.

有一些私有API,如PSYouTubeExtractor.

我认为你需要有视频的URL用于下载目的.

原文链接:https://www.f2er.com/iOS/333249.html

猜你在找的iOS相关文章