问题
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