【发布时间】:2017-07-08 17:33:10
【问题描述】:
我正在尝试使用此方法检测从 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
【问题讨论】:
-
请不要在您的问题中添加不相关的标签。您的问题与物理 iPhone 无关,也与 Xcode IDE 无关。请在使用前阅读标签的描述。谢谢。
-
.m3u8for Vimeo 是一种众所周知的视频“格式”。你可以查查看。至于其他,它不是至少有一些<video...>标签或播放器吗? -
没有文件扩展名,因为 UIWebView 正在播放流中的视频 ;),所以不能直接下载。
-
@Larme m3u8 不是视频文件格式,而是播放列表文件。
-
@Larme ,看,我只需要一种从 youtube 等网站下载电影的方法......应用商店中有一些下载器,当您点击要观看的视频时,会自动发出警报出现,您可以下载视频文件