ALMoviePlayerController 0.3.0

ALMoviePlayerController 0.3.0

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2014年12月

未署名 维护。



  • 作者
  • Anthony Lobianco

ALMoviePlayerController 是 MPMoviePlayerController 的一个替换品,可以暴露 UI 元素并提供最大程度的自定义。

预览

ALMoviePlayerController 在 iPad 上的 iOS 7.0

Preview1

ALMoviePlayerController 在 iPhone 上的 iOS 6.1

Preview2

功能

  • MPMoviePlayerController 的一个直接替换品
  • 拥有许多不同的自定义选项,或者您可以采用苹果的股票外观
  • 支持横竖屏
  • 通用(支持 iPhone 和 iPad)
  • 支持 iOS 5.0 - iOS 7
  • 轻量级,稳定,具有小内存占用

安装

安装很简单。

手动安装

  1. 从 GitHub 下载 ZIP 文件,并将 ALMoviePlayerController 目录复制到您的项目中
  2. 在项目构建阶段链接 QuartzCore.frameworkMediaPlayer.framework
  3. 在您的视图选择中导入 #import "ALMoviePlayerController.h"

已测试环境

ALMoviePlayerController 已在 iOS 5.0、5.1 和 6.0(模拟器)、iOS 6.1(设备)以及 iOS 7.0(设备)上进行了测试。ALMoviePlayerController 要求启用 ARC。

示例用法

过程如下

  1. 创建一个 ALMoviePlayerController 电影播放器,并将其指定为自己的代理人
  2. 创建 ALMoviePlayerControls 控件(可选:自定义控件)
  3. 将控件分配给电影播放器
  4. 设置电影播放器的 contentURL,这将开始播放电影
  5. 在设备旋转时,如果不在全屏,则调整电影播放器的框架(当处于全屏时,旋转将自动处理)
  6. 实现 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许可证。基本上,如果您使用它,我会感激您的致谢。

享受吧!

(⌐■_■)