how to resolve when MPMediaItem assetURL is nil?
Asked Answered
B

0

13

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.

Benito answered 7/6, 2017 at 1:38 Comment(2)
Have you found any solution for the above issue?Phantom
No, @AbilashBNair. Apple's DTS says it's a feature enhancement that I should request through bugreporter.apple.com ... In the meantime, you should up vote this question to increase its visibility and maybe attract a useful answer from somebody.Benito

© 2022 - 2024 — McMap. All rights reserved.