gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 05:44:58 25 4
gpt4 key购买 nike

我正在尝试使用此方法检测从 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!)

}

此代码有效,但视频 URL 不包含任何视频文件扩展名: 例如这里是 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 

最佳答案

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

镜像服务器

这是因为在上传、下载和流媒体过程中,google 使用了域名为 googlevideo.com 的镜像服务器。

您在流媒体状态下访问链接视频。您将仅获得该镜像链接。Youtube 视频 驻留在这个镜像服务器中。

同样,Vimeo 正在使用镜像服务器 akamaized.net

引用SO POST澄清

从镜像 URL 解码视频链接

所以在这种情况下,我们需要的是 youtube 中视频的唯一 ID,并且可以通过附加 url 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.

有一些私有(private) API,例如 PSYouTubeExtractor .

我认为您需要有视频的 URL 才能下载。

关于ios - 在 UIWebView 中从 AVPlayer 获取视频 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44988987/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com