---恢复内容开始---
MPMoviePlayerController播放在线视频---恢复内容结束--
一 MPMoviePlayerController 简介
在iOS中播放视频可以使用MediaPlayer.framework种的MPMoviePlayerController类来完成,它支持本地视频和网络视频播放。这个类实现了MPMediaPlayback协议,因此具备一般的播放器控制功能,例如播放、暂停、停止等。下面列出了MPMoviePlayerController的常用属性和方法:
属性 说明
@property (nonatomic, copy) NSURL *contentURL 播放媒体URL,这个URL可以是本地路径,也可以是网络路径
@property (nonatomic, readonly) UIView *view 播放器视图,如果要显示视频必须将此视图添加到控制器视图中
@property (nonatomic, readonly) UIView *backgroundView 播放器背景视图
@property (nonatomic, readonly) MPMoviePlaybackState playbackState 媒体播放状态,枚举类型:
MPMoviePlaybackStateStopped:停止播放
MPMoviePlaybackStatePlaying:正在播放
MPMoviePlaybackStatePaused:暂停
MPMoviePlaybackStateInterrupted:中断
MPMoviePlaybackStateSeekingForward:向前定位
MPMoviePlaybackStateSeekingBackward:向后定位
@property (nonatomic, readonly) MPMovieLoadState loadState 网络媒体加载状态,枚举类型:
MPMovieLoadStateUnknown:位置类型
MPMovieLoadStatePlayable:
MPMovieLoadStatePlaythroughOK:这种状态如果shouldAutoPlay为YES将自动播放
MPMovieLoadStateStalled:停滞状态
@property (nonatomic) MPMovieControlStyle controlStyle 控制面板风格,枚举类型:
MPMovieControlStyleNone:无控制面板
MPMovieControlStyleEmbedded:嵌入视频风格
MPMovieControlStyleFullscreen:全屏
MPMovieControlStyleDefault:默认风格
@property (nonatomic) MPMovieRepeatMode repeatMode; 重复播放模式,枚举类型:
MPMovieRepeatModeNone:不重复,默认值
MPMovieRepeatModeOne:重复播放
@property (nonatomic) BOOL shouldAutoplay 当网络媒体缓存到一定数据时是否自动播放,默认为YES
@property (nonatomic, getter=isFullscreen) BOOL fullscreen 是否全屏展示,默认为NO,注意如果要通过此属性设置全屏必须在视图显示完成后设置,否则无效
@property (nonatomic) MPMovieScalingMode scalingMode 视频缩放填充模式,枚举类型:
MPMovieScalingModeNone:不进行任何缩放
MPMovieScalingModeAspectFit:固定缩放比例并且尽量全部展示视频,不会裁切视频
MPMovieScalingModeAspectFill:固定缩放比例并填充满整个视图展示,可能会裁切视频
MPMovieScalingModeFill:不固定缩放比例压缩填充整个视图,视频不会被裁切但是比例失衡
@property (nonatomic, readonly) BOOL readyForDisplay 是否有相关媒体被播放
@property (nonatomic, readonly) MPMovieMediaTypeMask movieMediaTypes 媒体类别,枚举类型:
MPMovieMediaTypeMaskNone:未知类型
MPMovieMediaTypeMaskVideo:视频
MPMovieMediaTypeMaskAudio:音频
@property (nonatomic) MPMovieSourceType movieSourceType 媒体源,枚举类型:
MPMovieSourceTypeUnknown:未知来源
MPMovieSourceTypeFile:本地文件
MPMovieSourceTypeStreaming:流媒体(直播或点播)
@property (nonatomic, readonly) NSTimeInterval duration 媒体时长,如果未知则返回0
@property (nonatomic, readonly) NSTimeInterval playableDuration 媒体可播放时长,主要用于表示网络媒体已下载视频时长
@property (nonatomic, readonly) CGSize naturalSize 视频实际尺寸,如果未知则返回CGSizeZero
@property (nonatomic) NSTimeInterval initialPlaybackTime 起始播放时间
@property (nonatomic) NSTimeInterval endPlaybackTime 终止播放时间
@property (nonatomic) BOOL allowsAirPlay 是否允许无线播放,默认为YES
@property (nonatomic, readonly, getter=isAirPlayVideoActive) BOOL airPlayVideoActive 当前媒体是否正在通过AirPlay播放
@property(nonatomic, readonly) BOOL isPreparedToPlay 是否准备好播放
@property(nonatomic) NSTimeInterval currentPlaybackTime 当前播放时间,单位:秒
@property(nonatomic) float currentPlaybackRate 当前播放速度,如果暂停则为0,正常速度为1.0,非0数据表示倍率
对象方法 说明
- (instancetype)initWithContentURL:(NSURL *)url 使用指定的URL初始化媒体播放控制器对象
- (void)setFullscreen:(BOOL)fullscreen animated:(BOOL)animated 设置视频全屏,注意如果要通过此方法设置全屏则必须在其视图显示之后设置,否则无效
- (void)requestThumbnailImagesAtTimes:(NSArray *)playbackTimes timeOption:(MPMovieTimeOption)option 获取在指定播放时间的视频缩略图,第一个参数是获取缩略图的时间点数组;第二个参数代表时间点精度,枚举类型:
MPMovieTimeOptionNearestKeyFrame:时间点附近
MPMovieTimeOptionExact:准确时间
- (void)cancelAllThumbnailImageRequests 取消所有缩略图获取请求
- (void)prepareToPlay 准备播放,加载视频数据到缓存,当调用play方法时如果没有准备好会自动调用此方法
- (void)play 开始播放
- (void)pause 暂停播放
- (void)stop 停止播放
- (void)beginSeekingForward 向前定位
- (void)beginSeekingBackward 向后定位
- (void)endSeeking 停止快进/快退
通知 说明
MPMoviePlayerScalingModeDidChangeNotification 视频缩放填充模式发生改变
MPMoviePlayerPlaybackDidFinishNotification 媒体播放完成或用户手动退出,具体完成原因可以通过通知userInfo中的key为MPMoviePlayerPlaybackDidFinishReasonUserInfoKey的对象获取
MPMoviePlayerPlaybackStateDidChangeNotification 播放状态改变,可配合playbakcState属性获取具体状态
MPMoviePlayerLoadStateDidChangeNotification 媒体网络加载状态改变
MPMoviePlayerNowPlayingMovieDidChangeNotification 当前播放的媒体内容发生改变
MPMoviePlayerWillEnterFullscreenNotification 将要进入全屏
MPMoviePlayerDidEnterFullscreenNotification 进入全屏后
MPMoviePlayerWillExitFullscreenNotification 将要退出全屏
MPMoviePlayerDidExitFullscreenNotification 退出全屏后
MPMoviePlayerIsAirPlayVideoActiveDidChangeNotification 当媒体开始通过AirPlay播放或者结束AirPlay播放
MPMoviePlayerReadyForDisplayDidChangeNotification 视频显示状态改变
MPMovieMediaTypesAvailableNotification 确定了媒体可用类型后
MPMovieSourceTypeAvailableNotification 确定了媒体来源后
MPMovieDurationAvailableNotification 确定了媒体播放时长后
MPMovieNaturalSizeAvailableNotification 确定了媒体的实际尺寸后
MPMoviePlayerThumbnailImageRequestDidFinishNotification 缩略图请求完成之后
MPMediaPlaybackIsPreparedToPlayDidChangeNotification 做好播放准备后
??附带:
@interface MPMoviePlayerController : NSObject <MPMediaPlayback> {
id _implementation;
}
@property (nonatomic, readonly) UIView *backgroundView;
@property (nonatomic, copy) NSURL *contentURL;
@property (nonatomic) int controlStyle;
@property (nonatomic) float currentPlaybackRate;
@property (nonatomic) double currentPlaybackTime;
@property (getter=isFullscreen, nonatomic) BOOL fullscreen;
@property (nonatomic, readonly) BOOL isPreparedToPlay;
@property (nonatomic, readonly) unsigned int loadState;
@property (nonatomic, readonly) int playbackState;
@property (nonatomic, readonly) BOOL readyForDisplay;
@property (nonatomic) int repeatMode;
@property (nonatomic) int scalingMode;
@property (nonatomic) BOOL shouldAutoplay;
@property (nonatomic, readonly) UIView *view;
// Image: /System/Library/Frameworks/MediaPlayer.framework/MediaPlayer
+ (void)allInstancesResignActive;
- (void).cxx_destruct;
- (BOOL)_isReadyForDisplay;
- (void)_resignActive;
- (BOOL)allowsAirPlay;
- (id)backgroundView;
- (void)beginSeekingBackward;
- (void)beginSeekingForward;
- (id)contentURL;
- (int)controlStyle;
- (float)currentPlaybackRate;
- (double)currentPlaybackTime;
- (void)dealloc;
- (double)duration;
- (double)endPlaybackTime;
- (void)endSeeking;
- (void)forwardInvocation:(id)arg1;
- (id)init;
- (id)initWithAsset:(id)arg1;
- (id)initWithContentURL:(id)arg1;
- (id)initWithPlayerItem:(id)arg1;
- (double)initialPlaybackTime;
- (BOOL)isAirPlayVideoActive;
- (BOOL)isFullscreen;
- (BOOL)isPreparedToPlay;
- (unsigned int)loadState;
- (id)methodSignatureForSelector:(SEL)arg1;
- (unsigned int)movieMediaTypes;
- (int)movieSourceType;
- (struct CGSize { float x1; float x2; })naturalSize;
- (void)pause;
- (void)play;
- (double)playableDuration;
- (int)playbackState;
- (void)prepareToPlay;
- (BOOL)readyForDisplay;
- (int)repeatMode;
- (int)scalingMode;
- (void)setAllowsAirPlay:(BOOL)arg1;
- (void)setContentURL:(id)arg1;
- (void)setControlStyle:(int)arg1;
- (void)setCurrentPlaybackRate:(float)arg1;
- (void)setCurrentPlaybackTime:(double)arg1;
- (void)setEndPlaybackTime:(double)arg1;
- (void)setFullscreen:(BOOL)arg1;
- (void)setFullscreen:(BOOL)arg1 animated:(BOOL)arg2;
- (void)setInitialPlaybackTime:(double)arg1;
- (void)setMovieSourceType:(int)arg1;
- (void)setRepeatMode:(int)arg1;
- (void)setScalingMode:(int)arg1;
- (void)setShouldAutoplay:(BOOL)arg1;
- (BOOL)shouldAutoplay;
- (void)skipToBeginning;
- (void)skipToNextItem;
- (void)skipToPreviousItem;
- (void)stop;
- (id)view;
// Image: /System/Library/Frameworks/iAd.framework/iAd
+ (void)preparePrerollAds;
- (id)_iAd_prerollController;
- (void)cancelPreroll;
- (void)playPrerollAdWithCompletionHandler:(id /* block */)arg1;
- (void)set_iAd_prerollController:(id)arg1;
@end