从NSNotification Asset中提取视频URL

时间:2016-06-25 04:44:06

标签: swift

对于像你一样的大程序员,我有一个小问题:)

我正在使用Swift 2构建IOS应用程序,我有一个工作正常的视频播放器,我只想使用nsnotification获取当前视频网址。

      in viewDidLoad()

    // add notification
    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(MZAvailableDownloadsViewController.videoHasStarted(_:)), name: "AVPlayerItemBecameCurrentNotification", object: nil)
    }

    func videoHasStarted(notification: NSNotification) {
       print(notification.object?.asset)
       // HOW TO EXTRACT VIDEO URL?
    }

输出结果为:

Optional(<AVURLAsset: 0x7faa81c02e20, URL = http://www.emanway.com/media/2016/06/22/17_Elahi.mp4>)

如您所见,我如何从输出中获取视频网址?提前致谢

1 个答案:

答案 0 :(得分:1)

AVURLAsset有URL property

要使用它,请将对象转换为AVURLAsset而不是AnyObject。

这样的事情应该有效:

if let asset = notification.object?.asset as? AVURLAsset {
    let videoURL = asset.URL

}
相关问题