如何获得MPMediaItem(有声读物)的各个章节 [英] How to get the MPMediaItem (audiobook) individual chapters

查看:115
本文介绍了如何获得MPMediaItem(有声读物)的各个章节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以使用以下方法从iPod库中获取所有有声读物:

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.

我知道您可以在iPod应用程序中通过在玩书时点按右上角的曲目"按钮来看到此内容.这会翻转播放器并显示章节列表.

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.

苹果是否正在使用私有API来获取此信息?

Is apple using a private API to get this?

推荐答案

要获取各个章节,您需要根据MPMediaItem的AssetURL属性创建一个AVAsset.

To get the individual chapters you need to create an AVAsset from the MPMediaItem's AssetURL property.

NSURL *assetURL = [mediaItem valueForProperty:MPMediaItemPropertyAssetURL];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:assetURL options:nil];
NSArray *locales = [asset availableChapterLocales];
NSArray *chapters = [asset chapterMetadataGroupsWithTitleLocale:locale containingItemsWithCommonKeys:[NSArray arrayWithObject:AVMetadataCommonKeyArtwork]];

获取URL并创建资产,检查章节的可用语言环境,然后从资产中获取章节.结果是一个AVTimedMetadataGroup数组,每个数组都包含一个CMTimeRange和一个AVMetadataItem s数组.每个AVMetadataItem都有一块元数据(例如,章节标题,章节插图).

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 AVTimedMetadataGroups that each contain a CMTimeRange and an array of AVMetadataItems. Each AVMetadataItem holds a piece of metadata (e.g. chapter title, chapter artwork).

根据

According to the documentation the only supported key is the AVMetadataCommonKeyArtwork.

这篇关于如何获得MPMediaItem(有声读物)的各个章节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆