1

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.

Christian Schlensker
  • 21,708
  • 19
  • 73
  • 121

1 Answers1

3

This is my code

MPMediaQuery *everything = [[MPMediaQuery alloc] init];
MPMediaPropertyPredicate *predicate = [MPMediaPropertyPredicate predicateWithValue:   [NSNumber numberWithInteger:MPMediaTypeAudioBook] forProperty:MPMediaItemPropertyMediaType];
[everything addFilterPredicate: predicate];
[everything setGroupingType: MPMediaGroupingAlbum];
Kjuly
  • 34,476
  • 22
  • 104
  • 118
zcx_hill
  • 46
  • 5
  • I tried this example but it doesn't seem to work for audiobooks that have more than one file. Instead of grouping them by their "album" it listed each individual file. Any idea how to get the list "exactly" how it appears in the Music app? – Hackmodford Feb 26 '15 at 17:53