[翻译] ALMoviePlayerController

ALMoviePlayerController

ALMoviePlayerController is a drop-in replacement for MPMoviePlayerController that exposes the UI elements and allows for maximum customization.

ALMoviePlayerController是MPMoviePlayerController的子类,允许你进行最大程度的定制.

Preview

ALMoviePlayerController on iPad, iOS 7.0

ALMoviePlayerController on iPhone, iOS 6.1

Features

  • Drop-in replacement for MPMoviePlayerController 继承自MPMoviePlayerController
  • Many different customization options, or you can go with the stock Apple look
  • Portrait and landscape support 支持横竖屏
  • Universal (iPhone and iPad) support 支持语言全球化
  • iOS 5.0 - iOS 7 support 支持iOS5 - iOS7
  • Lightweight, stable component with small memory footprint 轻量级

Installation

Installation is easy. 安装很简单

Cocoapods

  1. Add pod ‘ALMoviePlayerController‘, ‘~>0.3.0‘ to your Podfile 将ALMoviePlayerController添加到你的Podfile当中
  2. #import <ALMoviePlayerController/ALMoviePlayerController.h> in your view of choice 将<ALMoviePlayerController/ALMoviePlayerController.h>导入到你的头文件中

Manually

  1. Download the ZIP from Github and copy the ALMoviePlayerController directory to your project 下载ZIP包
  2. Link the QuartzCore.framework and MediaPlayer.framework library in your project‘s Build Phases 链接上QuartzCore.framework 与 MediaPlayer.framework
  3. #import "ALMoviePlayerController.h" in your view of choice 导入"ALMoviePlayerController.h"即可

Tested Environments

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.

Example Usage

The process is as follows:

使用流程:

  1. Create an ALMoviePlayerController movie player and assign yourself as its delegate 创建出实例对象并设置好代理
  2. Create the ALMoviePlayerControls controls (and optionally customize) 创建出ALMoviePlayerControls(可选)
  3. Assign the controls to the movie player 将控制器赋值给播放器
  4. Set the movie player‘s contentURL, which will start playing the movie 设置好电影播放的文件URL地址,用以控制电影开始播放
  5. On device rotation, adjust movie player frame if it‘s not in fullscreen (when in fullscreen, rotation is handled automatically)
  6. Implement 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:]

Delegate methods

@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];
}

Controls Properties

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;

Controls Styles

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;

Suggestions?

If you have any suggestions, let me know! If you find any bugs, please open a new issue.

Contact Me

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: [email protected]

Credits & License

ALMoviePlayerController is developed and maintained by Anthony Lobianco (@lobi4nco). Licensed under the MIT License. Basically, I would appreciate attribution if you use it.

Enjoy!

(?■_■)

时间: 2024-10-06 19:31:11

[翻译] ALMoviePlayerController的相关文章

在GlassFish应用服务器上创建并运行你的第一个Restful Web Service【翻译】

前言 本人一直开发Android应用,目前Android就业形势恶劣,甚至会一路下滑,因此决定学习服务器开发.采用的语言是java,IDE是Intellij,在下载Intellij的同时看到官网很多优秀的guide文章,于是按照guide成功完成了一个RESTful的demo.官方文档非常简洁,给我带来了很大的帮助,于是翻译之,希望对其他不愿意看原文的人有所帮助.由于水平有限,读者发现错误请指正,谢谢. 原文地址: https://www.jetbrains.com/help/idea/2016

Java 7 Concurrency Cookbook 翻译 序言

在日常的Java代码开发过程中,很难免地有对多线程的需求,掌握java多线程和并发的机制也是Java程序员写出更健壮和高效代码的基础.笔者找寻国内已出版的关于Java多线程和并发的的中文书籍和翻译书籍,大家一致推荐的是<Java Concurrency in Practice>,笔者暂时还没有看英文原版,笔者看的是它的翻译版<Java并发编程实战>,笔者读起来感觉并不通畅,不知道是翻译的问题还是原版本来就写得不够流畅,同时感觉知识的深度也超过了入门的需求. 笔者在机缘巧合之下,发现

[翻译] ORMLite document -- How to Use Part (二)

前言 此文档翻译于第一次学习 ORMLite 框架,如果发现当中有什么不对的地方,请指正.若翻译与原文档出现任何的不相符,请以原文档为准.原则上建议学习原英文文档. ---------------------------------------------------------------------------------------------- 二.如何使用 2.7 表的创建 ORMLite 提供了一些工具类为您存储在数据库中的类创建 table 和 schema. 2.7.1 Tabl

Reveal常用技巧(翻译来自Reveal官网blog)

翻译来自官网:http://revealapp.com/blog/reveal-common-tips-cn.html 以下基于Reveal 1.6. 用于快速上手的内置应用 刚刚下载Reveal,啥都还没配置呢,想先随便玩玩看,怎么办? 我们花了不少时间开发这个复杂程度类似与实际场景的Sample应用──Soundstagram(音频分享版的Instagram, ¯\_(ツ)_/¯),就是为了让大家能最快速地上手Reveal,尝试它的各种强大功能. 在 Help 菜单项中,点击 Inspect

qt 国际化(翻译时会触发changeEvent)

1. 修改工程文件 .pro ,加入翻译源文件 hello_world.ts: TRANSLATIONS += \        Resource/translations/hello_world.ts 写代码时需要注意下面两点:  2. 源码用 utf-8 字符集3. 源码中需要翻译的字符串必须用英文(不能有中文或其它语言),则需要用 tr()  函数.  例如: QMessageBox::information(this,tr("Information"),tr("Hel

还在吐槽翻译的外版书质量差吗?谈谈我个人的理解

很难想象哪个学习计算机技术的人是没看过这方面书籍的,如果只是在网上看看技术贴,那样得来的知识绝对是离散的,不系统的.而要真正学好一门学问(比如一门计算机语言或者一门技术),一本好书的作用是不言而喻的.很多人抱怨国人在技术图书方面抄来抄去,不求甚解,虽然出版图书者甚众,但最终成为精品者却凤毛麟角.于是,更多读者热衷于外版书.但显然,并非所有国人的外语水平都足以在阅读原版书籍时毫无障碍.那么退而求其次,寻求翻译版就成为一种看似不得已的选择. 不幸的是,网上对于翻译版书籍的吐槽可以说从未消停.我也看过

VLD 1.0 ReadMe翻译尝试

近期想学习下VLD的实现,打算从最简单的V1.0版本看起.以下是V1.0版本自己尝试翻译下,最新的2.x版本似乎强大了很多. 简介 Visual C++提供了内置的内存检测机制,但其充其量只满足了最小定位需求.VLD工具定位为内置内存泄漏的替代,提供了如下特性: 泄漏内存块的全调用栈回溯,包括文件及其行号: 泄漏内存完整转储(hex和ascii格式): 可定制的泄漏报告等级(报告的详细程度可配置) 相对于Purify和BoundsChecher工具其是免费的,而其他免费工具,往往需要入侵式代码.

如何调用有道翻译API(Java,HTTP)

申请Key 首先如图进入有道翻译,在下方点击"有道翻译API". 紧接着来调用数据接口,按提示完成下列输入框. 如下图所示,已经申请成功了. 下图是官方给的示例,可以有xml和json.jsonp等三种数据格式. 代码(Java) public class TestPost { public static void main(String[] args) { new ReadByPost().start(); } } class ReadByPost extends Thread{ @

Android studio project文件结构翻译

Android studio project文件结构翻译 个人翻译,用作备忘. 链接地址:https://developer.android.com/tools/projects/index.html#ApplicationModules Android Project Files Studio的项目文件和设置,设置的作用范围包含所有的module. 以以下的demo为例. .git:git版本控制的文件存放目录. .gradle:gradle执行一些编译所生成的目录 Idea: 由Intell