I know I can get all the audiobooks from the iPod library with:
MPMediaPropertyPredicate *abPredicate =
[MPMediaPropertyPredicate predicateWithValue:[NSNumber numberWithInt:MPMediaTypeAudioBook]
forProperty:MPMediaItemPropertyMediaType];
MPMediaQuery *abQuery = [[MPMediaQuery alloc] init];
[abQuery addFilterPredicate:abPredicate];
[abQuery setGroupingType:MPMediaGroupingAlbum];
NSArray *books = [abQuery collections];
And I can get the parts/files for each book by using this:
[book items];
What I cant figure out is how to get the separate chapters that make up each part.
I know you can see this in the iPod application by tapping the "track" button in the upper right corner while playing a book. This flips the player around and shows the list of chapters.
Is apple using a private API to get this?
To get the individual chapters you need to create an
AVAsset
from theMPMediaItem
's AssetURL property.Get the url and create the asset, check the available locales for the chapter, and get the chapters from the asset. The result is an array of
AVTimedMetadataGroup
s that each contain aCMTimeRange
and an array ofAVMetadataItem
s. EachAVMetadataItem
holds a piece of metadata (e.g. chapter title, chapter artwork).According to the documentation the only supported key is the
AVMetadataCommonKeyArtwork
.