ijkplayer源碼閱讀02-播放協(xié)議

概述

ijkplayer 是Bilibili開發(fā)并開源的輕量級視頻播放器,支持本地網(wǎng)絡視頻播放以及流媒體播放,支持iOS和Android平臺。ijkplayer基于 FFmpeg 是一套可以用來記錄、轉(zhuǎn)換數(shù)字音頻、視頻,并能將其轉(zhuǎn)化為流的開源計算機程序。 FFmpeg 采用LGPL或GPL許可證,提供了錄制、轉(zhuǎn)換以及流化音視頻的完整解決方案,包括了領(lǐng)先的音、視頻編碼庫libavcodec等。

特性

platform | version | CPU| video-output|audio-output|hw-decoder
:---:|:---:|:---:|:---:|:---:
iOS | iOS 7.0+ | armv7, arm64, i386, x86_64|OpenGL ES 2.0|AudioQueue, AudioUnit|VideoToolbox (iOS 8+)
Android | API 9+ | ARMv7a, ARM64v8a, x86 |NativeWindow, OpenGL ES 2.0|AudioTrack, OpenSL ES|MediaCodec (API 16+, Android 4.1+)

IJKMediaPlayback

IJKMediaPlayback是 ijkplayer 中最重要的協(xié)議。由于 ijkplayer 中有幾種不同類型的播放器實現(xiàn)(如:基于AVPlayer實現(xiàn)的IJKAVMoviePlayerController,基于MPMoviePlayerController實現(xiàn)的IJKMPMoviePlayerController,基于FFmpeg實現(xiàn)的IJKFFMoviePlayerController)。為了統(tǒng)一播放行為,ijkplayer 使用了一套基本協(xié)議,使每種底層不同實現(xiàn)的播放器能為使用者提供統(tǒng)一的接口。

@protocol IJKMediaPlayback <NSObject>

- (void)prepareToPlay;
- (void)play;
- (void)pause;
- (void)stop;
- (BOOL)isPlaying;
- (void)shutdown;
- (void)setPauseInBackground:(BOOL)pause;

// 視頻畫面
@property(nonatomic, readonly)  UIView *view;
// 重播次數(shù)
@property(nonatomic)            NSTimeInterval currentPlaybackTime;
@property(nonatomic, readonly)  NSTimeInterval duration;
@property(nonatomic, readonly)  NSTimeInterval playableDuration;
@property(nonatomic, readonly)  NSInteger bufferingProgress;

@property(nonatomic, readonly)  BOOL isPreparedToPlay;
@property(nonatomic, readonly)  IJKMPMoviePlaybackState playbackState;
// 加載狀態(tài)
@property(nonatomic, readonly)  IJKMPMovieLoadState loadState;

@property(nonatomic, readonly) int64_t numberOfBytesTransferred;
// 視頻原始尺寸
@property(nonatomic, readonly) CGSize naturalSize;
// 畫面填充模式
@property(nonatomic) IJKMPMovieScalingMode scalingMode;
@property(nonatomic) BOOL shouldAutoplay;

@property (nonatomic) BOOL allowsMediaAirPlay;
@property (nonatomic) BOOL isDanmakuMediaAirPlay;
@property (nonatomic, readonly) BOOL airPlayMediaActive;

@property (nonatomic) float playbackRate;
@property (nonatomic) float playbackVolume;

// 視頻截圖
- (UIImage *)thumbnailImageAtCurrentTime;

#pragma mark Notifications

#ifdef __cplusplus
#define IJK_EXTERN extern "C" __attribute__((visibility ("default")))
#else
#define IJK_EXTERN extern __attribute__((visibility ("default")))
#endif

// -----------------------------------------------------------------------------
//  MPMediaPlayback.h

// Posted when the prepared state changes of an object conforming to the MPMediaPlayback protocol changes.
// This supersedes MPMoviePlayerContentPreloadDidFinishNotification.
IJK_EXTERN NSString *const IJKMPMediaPlaybackIsPreparedToPlayDidChangeNotification;

// -----------------------------------------------------------------------------
//  MPMoviePlayerController.h
//  Movie Player Notifications

// Posted when the scaling mode changes.
IJK_EXTERN NSString* const IJKMPMoviePlayerScalingModeDidChangeNotification;

// Posted when movie playback ends or a user exits playback.
IJK_EXTERN NSString* const IJKMPMoviePlayerPlaybackDidFinishNotification;
IJK_EXTERN NSString* const IJKMPMoviePlayerPlaybackDidFinishReasonUserInfoKey; // NSNumber (IJKMPMovieFinishReason)

// Posted when the playback state changes, either programatically or by the user.
IJK_EXTERN NSString* const IJKMPMoviePlayerPlaybackStateDidChangeNotification;

// Posted when the network load state changes.
IJK_EXTERN NSString* const IJKMPMoviePlayerLoadStateDidChangeNotification;

// Posted when the movie player begins or ends playing video via AirPlay.
IJK_EXTERN NSString* const IJKMPMoviePlayerIsAirPlayVideoActiveDidChangeNotification;

// -----------------------------------------------------------------------------
// Movie Property Notifications

// Calling -prepareToPlay on the movie player will begin determining movie properties asynchronously.
// These notifications are posted when the associated movie property becomes available.
IJK_EXTERN NSString* const IJKMPMovieNaturalSizeAvailableNotification;

// -----------------------------------------------------------------------------
//  Extend Notifications

IJK_EXTERN NSString *const IJKMPMoviePlayerVideoDecoderOpenNotification;
IJK_EXTERN NSString *const IJKMPMoviePlayerFirstVideoFrameRenderedNotification;
IJK_EXTERN NSString *const IJKMPMoviePlayerFirstAudioFrameRenderedNotification;

IJK_EXTERN NSString *const IJKMPMoviePlayerDidSeekCompleteNotification;
IJK_EXTERN NSString *const IJKMPMoviePlayerDidSeekCompleteTargetKey;
IJK_EXTERN NSString *const IJKMPMoviePlayerDidSeekCompleteErrorKey;
IJK_EXTERN NSString *const IJKMPMoviePlayerDidAccurateSeekCompleteCurPos;
IJK_EXTERN NSString *const IJKMPMoviePlayerAccurateSeekCompleteNotification;

@end

IJKMediaUrlOpenDelegate

IJKMediaUrlOpenDelegate 在 IJKFFMoviePlayerController 使用,當 ijkplayer 打開HTTP、TCP等相關(guān)URL的時候會回調(diào) - (void)willOpenUrl:(IJKMediaUrlOpenData*) urlOpenData 方法。

@protocol IJKMediaUrlOpenDelegate <NSObject>
- (void)willOpenUrl:(IJKMediaUrlOpenData*) urlOpenData;
@end

IJKMediaNativeInvokeDelegate

IJKMediaNativeInvokeDelegate 在 IJKFFMoviePlayerController 使用,當FFmpeg 在處理相關(guān)事件(如:AVAPP_EVENT_WILL_HTTP_OPEN、AVAPP_EVENT_DID_HTTP_OPENAVAPP_EVENT_WILL_HTTP_SEEK、AVAPP_EVENT_DID_HTTP_SEEK)的時候回調(diào)代理的 - (int)invoke:(IJKMediaEvent)event attributes:(NSDictionary *)attributes 方法。

@protocol IJKMediaNativeInvokeDelegate <NSObject>
- (int)invoke:(IJKMediaEvent)event attributes:(NSDictionary *)attributes;
@end

總結(jié)

ijkplayer 里面的協(xié)議比較簡單,協(xié)議的數(shù)量也不是很多。ijkplayer 提供了幾種不同實現(xiàn)的播放器,雖然這幾種播放器的實現(xiàn)不同,但都提供了統(tǒng)一的接口。因此,我們并不需要關(guān)心實現(xiàn)細節(jié)。

Demo地址 : https://github.com/QinminiOS/ijkplayer

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,323評論 25 708
  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,631評論 4 61
  • 第一次見到june是在韓國光州某座不知名山上的酒店里,我舉著新買的手機殼很驕傲的跟她說,看,新買的殼,五萬...
    二條九筒閱讀 363評論 2 4
  • 那些用心想留住的記憶,拼命沉淀下來的回憶,在時間的漫長侵蝕下,果真會逐漸褪去或明或暗的顏色,開始變得模糊不清。 ...
    小哲lee閱讀 636評論 0 0
  • 一、如何查看log 日志文件夾的默認存儲路徑是:/var/log 1、tail -f 查看實時日志 tail -f...
    墨墨如煙閱讀 590評論 2 0

友情鏈接更多精彩內(nèi)容