WPMoviePlayerController 0.4.0

WPMoviePlayerController 0.4.0

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

Seth Sandler 维护。



  • 作者
  • Anthony Lobianco

ALMoviePlayerController

ALMoviePlayerController 是 MPMoviePlayerController 的替代品,暴露 UI 元素,并提供最大程度的自定义。

预览

在 iPad 上运行的 ALMoviePlayerController,iOS 7.0

Preview1

在 iPhone 上运行的 ALMoviePlayerController,iOS 6.1

Preview2

特点

  • 用于 MPMoviePlayerController 的直接替换
  • 许多不同的自定义选项,或者可以选择默认的 Apple 观察效果
  • 支持横竖屏
  • 通用(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 和 7.0(设备)上进行了测试。ALMoviePlayerController 需要启用 ARC。

示例用法

过程如下

  1. 创建一个 ALMoviePlayerController Movie Player 并将其分配给您作为其代理
  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]

致谢 & 许可证

Anthony Lobianco (@lobi4nco) 开发了 upkeep ALMoviePlayerController。根据MIT许可证授权。基本上,如果您使用它,我会感谢您给予授权。

尽情享受!

(⌐■_■)