how to resolve when MPMediaItem assetURL is nil?

拈花ヽ惹草 提交于 2019-12-10 13:45:17

问题


I'm working on code that looks at the user's videos and passes them along to AVPlayer by way of an AVPlayerItem which takes a URL.

To get all the videos on an iOS device, you can do:

let videoNumber = MPMediaType.anyVideo.rawValue
let predicate = MPMediaPropertyPredicate.init(value: videoNumber, forProperty: MPMediaItemPropertyMediaType)
let query = MPMediaQuery.init()
query.addFilterPredicate(predicate)

if let items = query.items
{
    mediaCollection = MPMediaItemCollection(items: items)

    // -1 would indicate an error condition
    print("number of items in collection is \(mediaCollection?.count ?? -1)")
}

When you select the MPMediaItem you want to use from the items array, there should be an assetURL to go with it.

Trouble is, on my device, all of my assetURL properties are NULL. Coincidentally, while hasProtectedAsset for each of these items is false, isCloudItem for each of these items is true.

How can I come up with a valid assetURL that I can pass along to any media player? It feels somewhat bogus that developers can't get proper references & access to media in a user's iPod library.

来源:https://stackoverflow.com/questions/44402143/how-to-resolve-when-mpmediaitem-asseturl-is-nil

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!