Forum Xamarin.iOS
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

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.



  • 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.