List music on device using MPMediaQuery

I am trying to get a list of media on the device using the MPMediaQuery and I'm having a bit of trouble with the method signature. I need an MPMediaQuery with an MPMediaPropertyPredicate where the property is MPMediaItem.MediaTypeProperty and value is Music.

var query = new MPMediaQuery ();
var predicate = MPMediaPropertyPredicate.PredicateWithValue (MPMediaType.Music, MPMediaItem.MediaTypeProperty);
query.AddFilterPredicate (predicate);`

Trouble is, PredicateWithValue expects an NSObject and a String, MPMediaType.Music is an enum/nint. Which cannot be cast to an NSObject. Is this a regression bug in Xamarin, or am I using this code incorrectly? The official Apple documentation seems to suggest that this method should accept an NSString/string, rather than NSObject.

https://developer.apple.com/library/ios/documentation/Audio/Conceptual/iPodLibraryAccess_Guide/UsingTheiPodLibrary/UsingTheiPodLibrary.html#//apple_ref/doc/uid/TP40008765-CH101-SW1

Tagged:

Answers

  • NathanTaylor.SBNathanTaylor.SB USMember

    I was able to use FromObject(MPMediaType.Music) to get the desired result. This seems counterintuitive to me.

Sign In or Register to comment.