iOS query audiobooks in iPod library grouped by book

420 views Asked by At

I'm trying to replicate the iOS music app's audiobook functionality.

I want to query all audiobooks in the iPod library. It shouldn't show each individual part but should show each book. Tapping a book should then show the parts inside it.

I've tried using [MPMediaQuery audiobooksQuery]; but that just seems to fetch all individual parts.

I've also tried:

MPMediaPropertyPredicate *abPredicate =
[MPMediaPropertyPredicate predicateWithValue:[NSNumber numberWithInt:MPMediaTypeAudioBook] 
                                 forProperty:MPMediaItemPropertyMediaType];

MPMediaQuery *abQuery = [[MPMediaQuery alloc] init];
[abQuery addFilterPredicate:abPredicate];

but that does the same thing.

1

There are 1 answers

1
zcx_hill On BEST ANSWER

This is my code

MPMediaQuery *everything = [[MPMediaQuery alloc] init];
MPMediaPropertyPredicate *predicate = [MPMediaPropertyPredicate predicateWithValue:   [NSNumber numberWithInteger:MPMediaTypeAudioBook] forProperty:MPMediaItemPropertyMediaType];
[everything addFilterPredicate: predicate];
[everything setGroupingType: MPMediaGroupingAlbum];