ALMoviePlayerController 是 MPMoviePlayerController 的一个替换品,可以暴露 UI 元素并提供最大程度的自定义。
ALMoviePlayerController 在 iPad 上的 iOS 7.0
ALMoviePlayerController 在 iPhone 上的 iOS 6.1
MPMoviePlayerController
的一个直接替换品安装很简单。
QuartzCore.framework
和 MediaPlayer.framework
库#import "ALMoviePlayerController.h"
ALMoviePlayerController 已在 iOS 5.0、5.1 和 6.0(模拟器)、iOS 6.1(设备)以及 iOS 7.0(设备)上进行了测试。ALMoviePlayerController 要求启用 ARC。
过程如下
ALMoviePlayerController
电影播放器,并将其指定为自己的代理人ALMoviePlayerControls
控件(可选:自定义控件)contentURL
,这将开始播放电影ALMoviePlayerController
代理人方法在代码中
@property (nonatomic, strong) ALMoviePlayerController *moviePlayer;
//...
// create a movie player
self.moviePlayer = [[ALMoviePlayerController alloc] initWithFrame:self.view.frame];
self.moviePlayer.delegate = self; //IMPORTANT!
// create the controls
ALMoviePlayerControls *movieControls = [[ALMoviePlayerControls alloc] initWithMoviePlayer:self.moviePlayer style:ALMoviePlayerControlsStyleDefault];
// optionally customize the controls here...
/*
[movieControls setBarColor:[UIColor colorWithRed:195/255.0 green:29/255.0 blue:29/255.0 alpha:0.5]];
[movieControls setTimeRemainingDecrements:YES];
[movieControls setFadeDelay:2.0];
[movieControls setBarHeight:100.f];
[movieControls setSeekRate:2.f];
*/
// assign the controls to the movie player
[self.moviePlayer setControls:movieControls];
// add movie player to your view
[self.view addSubview:self.moviePlayer.view];
//set contentURL (this will automatically start playing the movie)
[self.moviePlayer setContentURL:[NSURL URLWithString:@"http://archive.org/download/WaltDisneyCartoons-MickeyMouseMinnieMouseDonaldDuckGoofyAndPluto/WaltDisneyCartoons-MickeyMouseMinnieMouseDonaldDuckGoofyAndPluto-HawaiianHoliday1937-Video.mp4"]];
在旋转时
if (!self.moviePlayer.isFullscreen) {
[self.moviePlayer setFrame:frame];
//"frame" is whatever the movie player's frame should be at that given moment
}
注意:您必须使用 [ALMoviePlayerController setFrame:]
来调整框架,而不是使用 [ALMoviePlayerController.view setFrame:]
@required
- (void)moviePlayerWillMoveFromWindow;
@optional
- (void)movieTimedOut;
注意: moviePlayerWillMoveFromWindow
对于全屏模式正常工作是必需的。它应该用来将电影播放器重新添加到视图控制器的视图中(因为在过渡到全屏时,它被移动到了 [[UIApplication sharedApplication] keyWindow]
)。
您的代码可能看起来像这样
- (void)moviePlayerWillMoveFromWindow {
if (![self.view.subviews containsObject:self.moviePlayer.view])
[self.view addSubview:self.moviePlayer.view];
[self.moviePlayer setFrame:frame];
}
ALMoviePlayerControls具有以下可编辑属性
/**
The style of the controls. Can be changed on the fly.
Default value is ALMoviePlayerControlsStyleDefault
*/
@property (nonatomic, assign) ALMoviePlayerControlsStyle style;
/**
The state of the controls.
*/
@property (nonatomic, readonly) ALMoviePlayerControlsState state;
/**
The color of the control bars.
Default value is black with a hint of transparency.
*/
@property (nonatomic, strong) UIColor *barColor;
/**
The height of the control bars.
Default value is 70.f for iOS7+ and 50.f for previous versions.
*/
@property (nonatomic, assign) CGFloat barHeight;
/**
The amount of time that the controls should stay on screen before automatically hiding.
Default value is 5 seconds.
*/
@property (nonatomic, assign) NSTimeInterval fadeDelay;
/**
The rate at which the movie should fastforward or rewind.
Default value is 3x.
*/
@property (nonatomic, assign) float seekRate;
/**
Should the time-remaining number decrement as the video plays?
Default value is NO.
*/
@property (nonatomic) BOOL timeRemainingDecrements;
/**
Are the controls currently showing on screen?
*/
@property (nonatomic, readonly, getter = isShowing) BOOL showing;
typedef enum {
/** Controls will appear in a bottom bar */
ALMoviePlayerControlsStyleEmbedded,
/** Controls will appear in a top bar and bottom bar */
ALMoviePlayerControlsStyleFullscreen,
/** Controls will appear as ALMoviePlayerControlsStyleFullscreen when in fullscreen and ALMoviePlayerControlsStyleEmbedded at all other times */
ALMoviePlayerControlsStyleDefault,
/** Controls will not appear */
ALMoviePlayerControlsStyleNone,
} ALMoviePlayerControlsStyle;
如果您有任何建议,请告诉我!如果您发现任何错误,请创建一个新的问题。
您可以通过以下地址随时联系我。如果您使用这个库,请在Twitter上告诉我您的想法。我很乐意听到您的反馈。
Github: alobi
Twitter: @lobi4nco
Email: [email protected]
ALMoviePlayerController由Anthony Lobianco (@lobi4nco) 开发和维护。使用MIT许可证。基本上,如果您使用它,我会感激您的致谢。
享受吧!
(⌐■_■)