标签:
ALMoviePlayerController
ALMoviePlayerController is a drop-in replacement for MPMoviePlayerController that exposes the UI elements and allows for maximum customization.
ALMoviePlayerController是MPMoviePlayerController的子类,允许你进行最大程度的定制.
ALMoviePlayerController on iPad, iOS 7.0
ALMoviePlayerController on iPhone, iOS 6.1
MPMoviePlayerController 继承自MPMoviePlayerController
Installation is easy. 安装很简单
pod ‘ALMoviePlayerController‘, ‘~>0.3.0‘
to your Podfile 将ALMoviePlayerController添加到你的Podfile当中#import <ALMoviePlayerController/ALMoviePlayerController.h>
in your view of choice 将<ALMoviePlayerController/ALMoviePlayerController.h>导入到你的头文件中QuartzCore.framework
and MediaPlayer.framework
library in your project‘s Build Phases 链接上QuartzCore.framework 与 MediaPlayer.framework#import "ALMoviePlayerController.h"
in your view of choice 导入"ALMoviePlayerController.h"即可ALMoviePlayerController has been tested to work on iOS 5.0, 5.1 and 6.0 (simulator), and iOS 6.1 and 7.0 (device). ALMoviePlayerController requires that ARC be enabled.
ALMoviePlayerController在iOS5.0,iOS5.1以及6.0,7.0上测试过,ALMoviePlayerController需要开启ARC.
The process is as follows:
使用流程:
ALMoviePlayerController
movie player and assign yourself as its delegate 创建出实例对象并设置好代理ALMoviePlayerControls
controls (and optionally customize) 创建出ALMoviePlayerControls(可选)contentURL
, which will start playing the movie 设置好电影播放的文件URL地址,用以控制电影开始播放ALMoviePlayerController
delegate methods 实现ALMoviePlayerController代理方法In code:
@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"]];
On rotation:
if (!self.moviePlayer.isFullscreen) {
[self.moviePlayer setFrame:frame];
//"frame" is whatever the movie player‘s frame should be at that given moment
}
Note: you MUST use [ALMoviePlayerController setFrame:]
to adjust frame, NOT[ALMoviePlayerController.view setFrame:]
@required
- (void)moviePlayerWillMoveFromWindow;
@optional
- (void)movieTimedOut;
Note: moviePlayerWillMoveFromWindow
is required for fullscreen mode to work properly. It should be used to re-add the movie player to your view controller‘s view (because during the transition to fullscreen, it was moved to [[UIApplication sharedApplication] keyWindow]
.
Your code might look something like this:
- (void)moviePlayerWillMoveFromWindow {
if (![self.view.subviews containsObject:self.moviePlayer.view])
[self.view addSubview:self.moviePlayer.view];
[self.moviePlayer setFrame:frame];
}
ALMoviePlayerControls has the following editable properties:
/**
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;
If you have any suggestions, let me know! If you find any bugs, please open a new issue.
You can reach me anytime at the addresses below. If you use the library, feel free to give me a shoutout on Twitter to let me know how you like it. I‘d love to hear your thoughts.
Github: alobi
Twitter: @lobi4nco
Email: anthony@lobian.co
ALMoviePlayerController is developed and maintained by Anthony Lobianco (@lobi4nco). Licensed under the MIT License. Basically, I would appreciate attribution if you use it.
Enjoy!
(?■_■)
标签:
原文地址:http://www.cnblogs.com/YouXianMing/p/4299029.html