AVPlayerItem 的內(nèi)容

AVPlayerItem 是對于被AVPlayer對象播放的asset進行模擬和記時,它提供了接口訪問媒體的不同時間杖剪、確定展示的大小挚赊、當(dāng)前時間的唯一標示符等等苗踪;

Associating Metadata for Playback with AVKit : 鏈接元素(對于AVKit上的Playback)
Notifications 通知
Instance Properties 實例屬性

開發(fā)中出現(xiàn)的問題:

一個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:只能夠占用一個位置 ,所以帚戳,應(yīng)該是先刪除玷或,然后再進行添加;

playItem 是通過kvo 監(jiān)聽方式片任;
ps: PlayItem 和 url以及asset之間的關(guān)系偏友;

對象相關(guān)的屬性(這些屬性可以查看官方文檔)
——————————————————————————————————————

  • (instancetype)assetWithURL:(NSURL *)URL;
    通過一個url返回一個asset對象

@property (nonatomic, readonly) CMTime duration; asset 資源的延時
如果providesPreciseDurationAndTiming == no,就會返回一個大概的值 对供;入托timing relate 被設(shè)置在初始化的時候位他,應(yīng)該是會返回精確的值; AVURLAssetPreferPreciseDurationAndTimingKey 鍵值犁钟;

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

@property (nonatomic, readonly) float preferredVolume;
變向選擇的卷

@property (nonatomic, readonly) CGAffineTransform preferredTransform;
這個是轉(zhuǎn)化

@property (nonatomic, readonly) CGSize naturalSize NS_DEPRECATED(10_7, 10_8, 4_0, 5_0);
默認的大欣庥铡(應(yīng)該過時了)

同步下載
@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; //規(guī)帶的媒體類型
  • (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); //創(chuàng)建日期
@property (nonatomic, readonly, nullable) NSString *lyrics; 對應(yīng)的文字詞
@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); //本地對象數(shù)組

  • (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

保護的內(nèi)容
@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); //執(zhí)行
@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的關(guān)系
@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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市涝动,隨后出現(xiàn)的幾起案子迈勋,更是在濱河造成了極大的恐慌,老刑警劉巖醋粟,帶你破解...
    沈念sama閱讀 211,561評論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件靡菇,死亡現(xiàn)場離奇詭異,居然都是意外死亡米愿,警方通過查閱死者的電腦和手機厦凤,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,218評論 3 385
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來育苟,“玉大人较鼓,你說我怎么就攤上這事。” “怎么了博烂?”我有些...
    開封第一講書人閱讀 157,162評論 0 348
  • 文/不壞的土叔 我叫張陵香椎,是天一觀的道長。 經(jīng)常有香客問我禽篱,道長畜伐,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 56,470評論 1 283
  • 正文 為了忘掉前任躺率,我火速辦了婚禮玛界,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘悼吱。我一直安慰自己慎框,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 65,550評論 6 385
  • 文/花漫 我一把揭開白布舆绎。 她就那樣靜靜地躺著鲤脏,像睡著了一般。 火紅的嫁衣襯著肌膚如雪吕朵。 梳的紋絲不亂的頭發(fā)上猎醇,一...
    開封第一講書人閱讀 49,806評論 1 290
  • 那天,我揣著相機與錄音努溃,去河邊找鬼硫嘶。 笑死,一個胖子當(dāng)著我的面吹牛梧税,可吹牛的內(nèi)容都是我干的沦疾。 我是一名探鬼主播,決...
    沈念sama閱讀 38,951評論 3 407
  • 文/蒼蘭香墨 我猛地睜開眼第队,長吁一口氣:“原來是場噩夢啊……” “哼哮塞!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起凳谦,我...
    開封第一講書人閱讀 37,712評論 0 266
  • 序言:老撾萬榮一對情侶失蹤忆畅,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后尸执,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體家凯,經(jīng)...
    沈念sama閱讀 44,166評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,510評論 2 327
  • 正文 我和宋清朗相戀三年如失,在試婚紗的時候發(fā)現(xiàn)自己被綠了绊诲。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 38,643評論 1 340
  • 序言:一個原本活蹦亂跳的男人離奇死亡褪贵,死狀恐怖掂之,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤板惑,帶...
    沈念sama閱讀 34,306評論 4 330
  • 正文 年R本政府宣布橄镜,位于F島的核電站偎快,受9級特大地震影響冯乘,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜晒夹,卻給世界環(huán)境...
    茶點故事閱讀 39,930評論 3 313
  • 文/蒙蒙 一裆馒、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧丐怯,春花似錦喷好、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,745評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至效览,卻和暖如春无切,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背丐枉。 一陣腳步聲響...
    開封第一講書人閱讀 31,983評論 1 266
  • 我被黑心中介騙來泰國打工哆键, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人瘦锹。 一個月前我還...
    沈念sama閱讀 46,351評論 2 360
  • 正文 我出身青樓籍嘹,卻偏偏與公主長得像,于是被迫代替她去往敵國和親弯院。 傳聞我的和親對象是個殘疾皇子辱士,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 43,509評論 2 348

推薦閱讀更多精彩內(nèi)容