asset这个词大家肯定看的很多.在Xcode工程中可以用asset特殊文件夹放一些资源文件.类似图片等.AVAsset也是表示和资源有关的.不过是和音视频资源有关的.
首先呢,这个AVAsset是一个类似NSOpeation的类,当然,我的意思不是说他是多线程的,而是说这个类是虚类
+ (instancetype)assetWithURL:(NSURL *)URL;
一般该方法创建出来的实例都是
AVAsset
的子类.类似AVURLAsset
这种类.
/// 资源的时长(可以理解为音乐一首歌的长度)
@property (nonatomic, readonly) CMTime duration;
/// AVAsset播放的自然速率.一般都为1.0.
@property (nonatomic, readonly) float preferredRate;
/// 表示AVAsset的首选音量.一般是1.0.
@property (nonatomic, readonly) float preferredVolume;
/// 音轨和视频轨道的方向
@property (nonatomic, readonly) CGAffineTransform preferredTransform;
/// 视频大小,已废弃
@property (nonatomic, readonly) CGSize naturalSize API_DEPRECATED("No longer supported", macos(10.7, 10.8), ios(4.0, 5.0), tvos(9.0, 9.0)) API_UNAVAILABLE(watchos);
/// 显示标准,AVAsset最佳显示模式
@property (nonatomic, readonly) AVDisplayCriteria *preferredDisplayCriteria API_AVAILABLE(tvos(11.2)) API_UNAVAILABLE(ios) API_UNAVAILABLE(macos, watchos);
/// 流资源的实时偏移程度
@property (nonatomic, readonly) CMTime minimumTimeOffsetFromLive API_AVAILABLE(macos(10.15), ios(13.0), tvos(13.0), watchos(6.0));
注:duration想要精确值的话,创建的时候传入AVURLAssetPreferPreciseDurationAndTimingKey
设置为YES是精确值.NO是估计值
/// 对外部媒体数据的引用的解析有关
typedef NS_OPTIONS(NSUInteger, AVAssetReferenceRestrictions) {
/// 不禁止
AVAssetReferenceRestrictionForbidNone = 0UL,
/// 禁止下载
AVAssetReferenceRestrictionForbidRemoteReferenceToLocal = (1UL << 0),
/// 禁止上传
AVAssetReferenceRestrictionForbidLocalReferenceToRemote = (1UL << 1),
/// 禁止远程跨站点引用
AVAssetReferenceRestrictionForbidCrossSiteReference = (1UL << 2),
/// 禁止除了存储在asset容器文件以外的本地引用
AVAssetReferenceRestrictionForbidLocalReferenceToLocal = (1UL << 3),
/// 禁止所有,只允许引用存储在asset容器文件中的媒体数据
AVAssetReferenceRestrictionForbidAll = 0xFFFFUL,
AVAssetReferenceRestrictionDefaultPolicy = AVAssetReferenceRestrictionForbidLocalReferenceToRemote
};
/// 默认为`AVAssetReferenceRestrictionForbidNone`
@property (nonatomic, readonly) AVAssetReferenceRestrictions referenceRestrictions API_AVAILABLE(macos(10.7), ios(5.0), tvos(9.0)) API_UNAVAILABLE(watchos);
/// AVAsset对象包含的AVAssetTracks数组
@property (nonatomic, readonly) NSArray *tracks;
/// 返回指定trackid的track.不存在就返回nil
- (nullable AVAssetTrack *)trackWithTrackID:(CMPersistentTrackID)trackID;
/// 返回指定媒体格式的tracks数组
- (NSArray *)tracksWithMediaType:(AVMediaType)mediaType;
/// 返回指定特征的tracks数组
- (NSArray *)tracksWithMediaCharacteristic:(AVMediaCharacteristic)mediaCharacteristic;
/// 返回AVAsset对象中的所有track组
@property (nonatomic, readonly) NSArray *trackGroups API_AVAILABLE(macos(10.9), ios(7.0), tvos(9.0), watchos(1.0));
说明一下.tracks(AVAssetTrack)是AVAsset的组成部分.可以理解为由多个AVAssetTrack组成的.
/// 返回asset的创建日期,可能为nil.如果asset可以转换为NSDate的形式存储创建日期.则通过[creationDate dateValue]获取.否则通过[creationDate stringValue]获取.
@property (nonatomic, readonly, nullable) AVMetadataItem *creationDate API_AVAILABLE(macos(10.8), ios(5.0), tvos(9.0), watchos(1.0));
/// 当前歌词
@property (nonatomic, readonly, nullable) NSString *lyrics;
/// 当前asset公共元数据
@property (nonatomic, readonly) NSArray *commonMetadata;
/// 所有元数据
@property (nonatomic, readonly) NSArray *metadata API_AVAILABLE(macos(10.10), ios(8.0), tvos(9.0), watchos(1.0));
/// 可用元数据格式字符串数组
@property (nonatomic, readonly) NSArray *availableMetadataFormats;
/// 所有元数据格式字符串数组
- (NSArray *)metadataForFormat:(AVMetadataFormat)format;
/// 可用章节区域
@property (readonly) NSArray *availableChapterLocales API_AVAILABLE(macos(10.7), ios(4.3), tvos(9.0), watchos(1.0));
/// 每个章节以AVMetadaItem包含章节标题和时间范围的形式返回
- (NSArray *)chapterMetadataGroupsWithTitleLocale:(NSLocale *)locale containingItemsWithCommonKeys:(nullable NSArray *)commonKeys API_AVAILABLE(macos(10.7), ios(4.3), tvos(9.0), watchos(1.0));
/// 每个章节以系统默认语言返回
- (NSArray *)chapterMetadataGroupsBestMatchingPreferredLanguages:(NSArray *)preferredLanguages API_AVAILABLE(macos(10.8), ios(6.0), tvos(9.0), watchos(1.0));
/// 会返回一个可用的媒体特征选项.(包括:AVMediaCharacteristicLegible字幕,AVMediaCharacteristicAudible音轨,AVMediaCharacteristicVisual视频)
@property (nonatomic, readonly) NSArray *availableMediaCharacteristicsWithMediaSelectionOptions API_AVAILABLE(macos(10.8), ios(5.0), tvos(9.0), watchos(1.0));
/// 通过`AVMediaCharacteristic `来获取不同的选项组(音频,字幕,视频)
- (nullable AVMediaSelectionGroup *)mediaSelectionGroupForMediaCharacteristic:(AVMediaCharacteristic)mediaCharacteristic API_AVAILABLE(macos(10.8), ios(5.0), tvos(9.0), watchos(1.0));
/// 所有媒体特诊的选项
@property (nonatomic, readonly) NSArray *allMediaSelections API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0));
/// asset是否有受保护的内容,有的话未经授权可能无法播放(即是playable的属性为YES也是这样)
@property (nonatomic, readonly) BOOL hasProtectedContent API_AVAILABLE(macos(10.7), ios(4.2), tvos(9.0)) API_UNAVAILABLE(watchos);
@end
/// asset能否通过片段进行拓展
@property (nonatomic, readonly) BOOL canContainFragments API_AVAILABLE(macos(10.11), ios(9.0), tvos(9.0)) API_UNAVAILABLE(watchos);
/*!
@property containsFragments
@abstract Indicates whether the asset is extended by at least one fragment.
@discussion For QuickTime movie files and MPEG-4 files, the value of this property is YES if canContainFragments is YES and at least one 'moof' box is present after the 'moov' box.
*/
/// 是否包含碎片.
@property (nonatomic, readonly) BOOL containsFragments API_AVAILABLE(macos(10.11), ios(9.0), tvos(9.0)) API_UNAVAILABLE(watchos);
/// 碎片的总持续时间.如果没有该属性的值为`overallDurationHint `
@property (nonatomic, readonly) CMTime overallDurationHint API_AVAILABLE(macos(10.12.2), ios(10.2), tvos(10.2), watchos(3.2));
/// 是否能播放,当为NO的时候可以尝试播放,但是播放体验可能不符合预期.(AVAsset或者其URL能否用于初始化AVPlayerItem)
@property (nonatomic, readonly, getter=isPlayable) BOOL playable API_AVAILABLE(macos(10.7), ios(4.3), tvos(9.0), watchos(1.0));
/// 能否导出(通过AVAssetExportSession)
@property (nonatomic, readonly, getter=isExportable) BOOL exportable API_AVAILABLE(macos(10.7), ios(4.3), tvos(9.0)) API_UNAVAILABLE(watchos);
/// 能否提取其中信息(通过`AVAssetReader`)
@property (nonatomic, readonly, getter=isReadable) BOOL readable API_AVAILABLE(macos(10.7), ios(4.3), tvos(9.0)) API_UNAVAILABLE(watchos);
/// 资源能否在AVCompositionTrack实例的一个段中使用
@property (nonatomic, readonly, getter=isComposable) BOOL composable API_AVAILABLE(macos(10.7), ios(4.3), tvos(9.0), watchos(1.0));
/// 能否将AVAsset写入相册
@property (nonatomic, readonly, getter=isCompatibleWithSavedPhotosAlbum) BOOL compatibleWithSavedPhotosAlbum API_AVAILABLE(ios(5.0), tvos(9.0)) API_UNAVAILABLE(watchos) API_UNAVAILABLE(macos);
/// asset是否可以使用`AirPlay Video`在外部设备播放.
@property (nonatomic, readonly, getter=isCompatibleWithAirPlayVideo) BOOL compatibleWithAirPlayVideo API_AVAILABLE(macos(10.11), ios(9.0), tvos(9.0)) API_UNAVAILABLE(watchos);