AVPlayerItem 是对于被AVPlayer对象播放的asset进行模拟和记时,它提供了接口访问媒体的不同时间、确定展示的大小、当前时间的唯一标示符等等;
Associating Metadata for Playback with AVKit : 链接元素(对于AVKit上的Playback)
Notifications 通知
Instance Properties 实例属性
开发中出现的问题:
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
- (nullable AVAssetTrack *)trackWithTrackID:(CMPersistentTrackID)trackID; //轨道的id
- (NSArray
*)tracksWithMediaType:(NSString *)mediaType; //规带的媒体类型 - (NSArray
*)tracksWithMediaCharacteristic:(NSString *)mediaCharacteristic; //媒体的标示
@property (nonatomic, readonly) NSArray*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
@property (nonatomic, readonly) NSArray
@property (nonatomic, readonly) NSArray
- (NSArray
*)metadataForFormat:(NSString *)format; 通过格式来获取item
@end
字幕的检测
@interface AVAsset (AVAssetChapterInspection)
@property (readonly) NSArray
- (NSArray
*)chapterMetadataGroupsWithTitleLocale:(NSLocale *)locale containingItemsWithCommonKeys:(nullable NSArray *)commonKeys NS_AVAILABLE(10_7, 4_3); - (NSArray
*)chapterMetadataGroupsBestMatchingPreferredLanguages:(NSArray *)preferredLanguages NS_AVAILABLE(10_8, 6_0);
@end
媒体选择
@interface AVAsset (AVAssetMediaSelection)
@property (nonatomic, readonly) NSArray
- (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
*)audiovisualTypes NS_AVAILABLE(10_7, 5_0); //音频的类型 - (NSArray
*)audiovisualMIMETypes NS_AVAILABLE(10_7, 5_0); - (BOOL)isPlayableExtendedMIMEType: (NSString *)extendedMIMEType NS_AVAILABLE(10_7, 5_0);
- (instancetype)URLAssetWithURL:(NSURL *)URL options:(nullable NSDictionary
*)options;
- (instancetype)initWithURL:(NSURL *)URL options:(nullable NSDictionary
*)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
{
@private
AVFragmentedAssetInternal *_fragmentedAsset;
}
- (instancetype)fragmentedAssetWithURL:(NSURL *)URL options:(nullable NSDictionary
*)options;
@property (nonatomic, readonly) NSArray*tracks;
@end
@interface AVFragmentedAsset (AVFragmentedAssetTrackInspection)
- (nullable AVFragmentedAssetTrack *)trackWithTrackID:(CMPersistentTrackID)trackID;
- (NSArray
*)tracksWithMediaType:(NSString *)mediaType; - (NSArray
*)tracksWithMediaCharacteristic:(NSString *)mediaCharacteristic;
@end
@class AVFragmentedAssetMinderInternal;
NS_CLASS_AVAILABLE_MAC(10_11)
@interface AVFragmentedAssetMinder : NSObject
{
@private
AVFragmentedAssetMinderInternal *_fragmentedAssetMinder;
}
- (instancetype)fragmentedAssetMinderWithAsset:(AVAsset
*)asset mindingInterval:(NSTimeInterval)mindingInterval;
@property (nonatomic) NSTimeInterval mindingInterval;
@property (nonatomic, readonly) NSArray*> *assets;
- (void)addFragmentedAsset:(AVAsset
*)asset; - (void)removeFragmentedAsset:(AVAsset
*)asset;
@end
源码链接:
https://github.com/helinyu/test_AVPlayer