AVPlayerItem 的内容

作者: helinyu | 来源:发表于2016-10-31 20:07 被阅读3684次

    AVPlayerItem 是对于被AVPlayer对象播放的asset进行模拟和记时,它提供了接口访问媒体的不同时间、确定展示的大小、当前时间的唯一标示符等等;

    Associating Metadata for Playback with AVKit : 链接元素(对于AVKit上的Playback)
    Notifications 通知
    Instance Properties 实例属性

    开发中出现的问题:

    一个quene中不能够有两个同样PlayItem
    Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'An AVPlayerItem can occupy only one position in a player's queue at a time.'
    ps:只能够占用一个位置 ,所以,应该是先删除,然后再进行添加;

    playItem 是通过kvo 监听方式;
    ps: PlayItem 和 url以及asset之间的关系;

    对象相关的属性(这些属性可以查看官方文档)
    ——————————————————————————————————————

    • (instancetype)assetWithURL:(NSURL *)URL;
      通过一个url返回一个asset对象

    @property (nonatomic, readonly) CMTime duration; asset 资源的延时
    如果providesPreciseDurationAndTiming == no,就会返回一个大概的值 ;入托timing relate 被设置在初始化的时候,应该是会返回精确的值; AVURLAssetPreferPreciseDurationAndTimingKey 键值;

    @property (nonatomic, readonly) float preferredRate;
    自然播放的速度

    @property (nonatomic, readonly) float preferredVolume;
    变向选择的卷

    @property (nonatomic, readonly) CGAffineTransform preferredTransform;
    这个是转化

    @property (nonatomic, readonly) CGSize naturalSize NS_DEPRECATED(10_7, 10_8, 4_0, 5_0);
    默认的大小(应该过时了)

    同步下载
    @interface AVAsset (AVAssetAsynchronousLoading)
    @property (nonatomic, readonly) BOOL providesPreciseDurationAndTiming;

    • (void)cancelLoading;
      @end

    偏向的限制
    @interface AVAsset (AVAssetReferenceRestrictions)
    typedef NS_OPTIONS(NSUInteger, AVAssetReferenceRestrictions) {
    AVAssetReferenceRestrictionForbidNone = 0UL,
    AVAssetReferenceRestrictionForbidRemoteReferenceToLocal = (1UL << 0),
    AVAssetReferenceRestrictionForbidLocalReferenceToRemote = (1UL << 1),
    AVAssetReferenceRestrictionForbidCrossSiteReference = (1UL << 2),
    AVAssetReferenceRestrictionForbidLocalReferenceToLocal = (1UL << 3),
    AVAssetReferenceRestrictionForbidAll = 0xFFFFUL,
    };
    @property (nonatomic, readonly) AVAssetReferenceRestrictions referenceRestrictions NS_AVAILABLE(10_7, 5_0);
    @end

    轨道检测
    @interface AVAsset (AVAssetTrackInspection)
    @property (nonatomic, readonly) NSArray<AVAssetTrack *> *tracks; 读取的轨道

    • (nullable AVAssetTrack *)trackWithTrackID:(CMPersistentTrackID)trackID; //轨道的id
    • (NSArray<AVAssetTrack *> *)tracksWithMediaType:(NSString *)mediaType; //规带的媒体类型
    • (NSArray<AVAssetTrack *> *)tracksWithMediaCharacteristic:(NSString *)mediaCharacteristic; //媒体的标示
      @property (nonatomic, readonly) NSArray<AVAssetTrackGroup *> *trackGroups NS_AVAILABLE(10_9, 7_0); //轨道组
      @end

    AVAsset元组的读取
    @interface AVAsset (AVAssetMetadataReading)
    @property (nonatomic, readonly, nullable) AVMetadataItem *creationDate NS_AVAILABLE(10_8, 5_0); //创建日期
    @property (nonatomic, readonly, nullable) NSString *lyrics; 对应的文字词
    @property (nonatomic, readonly) NSArray<AVMetadataItem *> *commonMetadata; 公共的元素
    @property (nonatomic, readonly) NSArray<AVMetadataItem *> *metadata NS_AVAILABLE(10_10, 8_0); 元素
    @property (nonatomic, readonly) NSArray<NSString *> *availableMetadataFormats; 元素中使用的类型

    • (NSArray<AVMetadataItem *> *)metadataForFormat:(NSString *)format; 通过格式来获取item
      @end

    字幕的检测
    @interface AVAsset (AVAssetChapterInspection)
    @property (readonly) NSArray<NSLocale *> *availableChapterLocales NS_AVAILABLE(10_7, 4_3); //本地对象数组

    • (NSArray<AVTimedMetadataGroup *> *)chapterMetadataGroupsWithTitleLocale:(NSLocale *)locale containingItemsWithCommonKeys:(nullable NSArray<NSString *> *)commonKeys NS_AVAILABLE(10_7, 4_3);
    • (NSArray<AVTimedMetadataGroup *> *)chapterMetadataGroupsBestMatchingPreferredLanguages:(NSArray<NSString *> *)preferredLanguages NS_AVAILABLE(10_8, 6_0);
      @end

    媒体选择
    @interface AVAsset (AVAssetMediaSelection)
    @property (nonatomic, readonly) NSArray<NSString *> *availableMediaCharacteristicsWithMediaSelectionOptions NS_AVAILABLE(10_8, 5_0); //有用的媒体字符特征

    • (nullable AVMediaSelectionGroup *)mediaSelectionGroupForMediaCharacteristic:(NSString *)mediaCharacteristic NS_AVAILABLE(10_8, 5_0); //媒体选择组
      @property (nonatomic, readonly) AVMediaSelection *preferredMediaSelection NS_AVAILABLE(10_11, 9_0); //媒体的选择
      @end

    保护的内容
    @interface AVAsset (AVAssetProtectedContent)
    @property (nonatomic, readonly) BOOL hasProtectedContent NS_AVAILABLE(10_7, 4_2);
    @end

    碎片
    @interface AVAsset (AVAssetFragments)
    @property (nonatomic, readonly) BOOL canContainFragments NS_AVAILABLE(10_11, 9_0);
    @property (nonatomic, readonly) BOOL containsFragments NS_AVAILABLE(10_11, 9_0);
    @end

    使用情况
    @interface AVAsset (AVAssetUsability)
    @property (nonatomic, readonly, getter=isPlayable) BOOL playable NS_AVAILABLE(10_7, 4_3);播放能力
    @property (nonatomic, readonly, getter=isExportable) BOOL exportable NS_AVAILABLE(10_7, 4_3); //执行
    @property (nonatomic, readonly, getter=isReadable) BOOL readable NS_AVAILABLE(10_7, 4_3); //读取能力
    @property (nonatomic, readonly, getter=isComposable) BOOL composable NS_AVAILABLE(10_7, 4_3); // 组成
    @property (nonatomic, readonly, getter=isCompatibleWithSavedPhotosAlbum) BOOL compatibleWithSavedPhotosAlbum NS_AVAILABLE_IOS(5_0); // 保存到相册
    @property (nonatomic, readonly, getter=isCompatibleWithAirPlayVideo) BOOL compatibleWithAirPlayVideo NS_AVAILABLE(10_11, 9_0); //与airplay的关系
    @end

    AVF_EXPORT NSString *const AVURLAssetPreferPreciseDurationAndTimingKey NS_AVAILABLE(10_7, 4_0);
    AVF_EXPORT NSString *const AVURLAssetReferenceRestrictionsKey NS_AVAILABLE(10_7, 5_0);
    AVF_EXPORT NSString *const AVURLAssetHTTPCookiesKey NS_AVAILABLE_IOS(8_0);
    AVF_EXPORT NSString *const AVURLAssetAllowsCellularAccessKey NS_AVAILABLE_IOS(10_0);

    @interface AVURLAsset : AVAsset

    • (NSArray<NSString *> *)audiovisualTypes NS_AVAILABLE(10_7, 5_0); //音频的类型
    • (NSArray<NSString *> *)audiovisualMIMETypes NS_AVAILABLE(10_7, 5_0);
    • (BOOL)isPlayableExtendedMIMEType: (NSString *)extendedMIMEType NS_AVAILABLE(10_7, 5_0);
    • (instancetype)URLAssetWithURL:(NSURL *)URL options:(nullable NSDictionary<NSString *, id> *)options;
    • (instancetype)initWithURL:(NSURL *)URL options:(nullable NSDictionary<NSString *, id> *)options NS_DESIGNATED_INITIALIZER;
      @property (nonatomic, readonly, copy) NSURL *URL;
      @end

    @class AVAssetResourceLoader;
    @interface AVURLAsset (AVURLAssetURLHandling)
    @property (nonatomic, readonly) AVAssetResourceLoader *resourceLoader NS_AVAILABLE(10_9, 6_0);
    @end

    @class AVAssetCache;
    @interface AVURLAsset (AVURLAssetCache)
    @property (nonatomic, readonly, nullable) AVAssetCache *assetCache NS_AVAILABLE(10_12, 10_0);
    @end

    @interface AVURLAsset (AVAssetCompositionUtility )

    • (nullable AVAssetTrack *)compatibleTrackForCompositionTrack:(AVCompositionTrack *)compositionTrack;
      @end
      AVF_EXPORT NSString *const AVAssetDurationDidChangeNotification NS_AVAILABLE(10_11, 9_0);
      AVF_EXPORT NSString *const AVAssetContainsFragmentsDidChangeNotification NS_AVAILABLE_MAC(10_11);
      AVF_EXPORT NSString *const AVAssetWasDefragmentedNotification NS_AVAILABLE_MAC(10_11);
      AVF_EXPORT NSString *const AVAssetChapterMetadataGroupsDidChangeNotification NS_AVAILABLE(10_11, 9_0);
      AVF_EXPORT NSString *const AVAssetMediaSelectionGroupsDidChangeNotification NS_AVAILABLE(10_11, 9_0);
      @end

    @protocol AVFragmentMinding
    @property (nonatomic, readonly, getter=isAssociatedWithFragmentMinder) BOOL associatedWithFragmentMinder NS_AVAILABLE_MAC(10_11);
    @end

    @class AVFragmentedAssetInternal;
    NS_CLASS_AVAILABLE_MAC(10_11)
    @interface AVFragmentedAsset : AVURLAsset <AVFragmentMinding>
    {
    @private
    AVFragmentedAssetInternal *_fragmentedAsset;
    }

    • (instancetype)fragmentedAssetWithURL:(NSURL *)URL options:(nullable NSDictionary<NSString *, id> *)options;
      @property (nonatomic, readonly) NSArray<AVFragmentedAssetTrack *> *tracks;
      @end

    @interface AVFragmentedAsset (AVFragmentedAssetTrackInspection)

    • (nullable AVFragmentedAssetTrack *)trackWithTrackID:(CMPersistentTrackID)trackID;
    • (NSArray<AVFragmentedAssetTrack *> *)tracksWithMediaType:(NSString *)mediaType;
    • (NSArray<AVFragmentedAssetTrack *> *)tracksWithMediaCharacteristic:(NSString *)mediaCharacteristic;
      @end

    @class AVFragmentedAssetMinderInternal;
    NS_CLASS_AVAILABLE_MAC(10_11)
    @interface AVFragmentedAssetMinder : NSObject
    {
    @private
    AVFragmentedAssetMinderInternal *_fragmentedAssetMinder;
    }

    • (instancetype)fragmentedAssetMinderWithAsset:(AVAsset<AVFragmentMinding> *)asset mindingInterval:(NSTimeInterval)mindingInterval;
      @property (nonatomic) NSTimeInterval mindingInterval;
      @property (nonatomic, readonly) NSArray<AVAsset<AVFragmentMinding> *> *assets;
    • (void)addFragmentedAsset:(AVAsset<AVFragmentMinding> *)asset;
    • (void)removeFragmentedAsset:(AVAsset<AVFragmentMinding> *)asset;
      @end

    源码链接:
    https://github.com/helinyu/test_AVPlayer

    相关文章

      网友评论

      • LD_左岸:AVPlayerItem 拿他的duration 老是为nan 可咋解决呢
        helinyu:@左岸__ 你的代码是怎么写的?有代码就好找原因了

      本文标题:AVPlayerItem 的内容

      本文链接:https://www.haomeiwen.com/subject/fsvputtx.html