Skip to content

Commit

Permalink
Merge pull request #1 from Ekhoo/dev
Browse files Browse the repository at this point in the history
Bêta EKVideoController
  • Loading branch information
Ekhoo committed Mar 8, 2015
2 parents da7d070 + d5c4fec commit 2e3f48f
Show file tree
Hide file tree
Showing 22 changed files with 1,106 additions and 0 deletions.
67 changes: 67 additions & 0 deletions EKVideoController/EKVideoController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// EKVideoController.h
// EKVideoControllerExample
//
// Created by Lucas Ortis on 06/03/2015.
// Copyright (c) 2015 Ekhoo. All rights reserved.
//

#import <UIKit/UIKit.h>

#define EK_SCREEN_BOUNDS [[UIScreen mainScreen] bounds]
#define EK_SCREEN_WIDTH [[[UIScreen mainScreen] bounds] width]
#define EK_SCREEN_HEIGHT [[[UIScreen mainScreen] bounds] height]

@interface EKVideoController : UIViewController

//
// VideoPath can be a local file path or an URL.
// When it's setted, the view controller initialize and add the video to the view.
//
@property(nonatomic, strong) NSString *videoPath;

//
// Determine how the view controller repeats the playback of the video.
// Default value is YES.
//
@property(nonatomic, assign) BOOL repeat;

//
// Determine the speed of the video.
// Default value is 1.0f;
//
@property(nonatomic, assign) CGFloat videoSpeed;

//
// Determine the mask color.
// Default value is [UIColor clearColor].
//
@property(nonatomic, strong) UIColor *maskTintColor;

//
// Determine the transparency of the mask.
// Default value is 0.0f.
//
@property(nonatomic, assign) CGFloat maskAlpha;

//
// Play the video.
//
- (void)play;

//
// Stop the video.
//
- (void)stop;

//
// Pause the video.
//
- (void)pause;

//
// Restart the video from the beginning.
//
- (void)restart;

@end
133 changes: 133 additions & 0 deletions EKVideoController/EKVideoController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
//
// EKVideoController.m
// EKVideoControllerExample
//
// Created by Lucas Ortis on 06/03/2015.
// Copyright (c) 2015 Ekhoo. All rights reserved.
//
@import MediaPlayer;

#import "EKVideoController.h"

@interface EKVideoController()

@property(nonatomic, strong) MPMoviePlayerController *moviePlayer;
@property(nonatomic, strong) UIView *moviePlayerMask;

@end

@implementation EKVideoController

#pragma mark - Life cycle

- (instancetype)init {
self = [super init];

if (self) {
_repeat = YES;
_videoSpeed = 1.0f;
_maskTintColor = [UIColor clearColor];
_maskAlpha = 0.0f;
}

return self;
}

- (void)viewDidLoad {
[super viewDidLoad];

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}

#pragma mark - Setters

- (void)setVideoPath:(NSString *)videoPath {
NSParameterAssert(videoPath);

_videoPath = videoPath;

/*** Movie player ***/
if (_moviePlayer) {
[_moviePlayer stop];
[_moviePlayer.view removeFromSuperview];
_moviePlayer = nil;
}

_moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:videoPath]];
_moviePlayer.view.frame = EK_SCREEN_BOUNDS;
_moviePlayer.fullscreen = YES;
_moviePlayer.controlStyle = MPMovieControlStyleNone;
_moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
_moviePlayer.repeatMode = self.repeat ? MPMovieRepeatModeOne : MPMovieRepeatModeNone;
_moviePlayer.currentPlaybackRate = self.videoSpeed;

/*** Movie player mask ***/
if (_moviePlayerMask) {
[_moviePlayerMask removeFromSuperview];
_moviePlayerMask = nil;
}

_moviePlayerMask = [[UIView alloc] initWithFrame:EK_SCREEN_BOUNDS];
_moviePlayerMask.alpha = self.maskAlpha;
_moviePlayerMask.backgroundColor = self.maskTintColor;

[self.view addSubview:self.moviePlayer.view];
[self.view addSubview:self.moviePlayerMask];
[self.view sendSubviewToBack:self.moviePlayer.view];
}

- (void)setRepeat:(BOOL)repeat {
NSParameterAssert(self.moviePlayer);

_repeat = repeat;

_moviePlayer.repeatMode = repeat ? MPMovieRepeatModeOne : MPMovieRepeatModeNone;
}

- (void)setVideoSpeed:(CGFloat)videoSpeed {
NSParameterAssert(self.moviePlayer);

_videoSpeed = videoSpeed;
self.moviePlayer.currentPlaybackRate = _videoSpeed;
}

- (void)setMaskTintColor:(UIColor *)maskTintColor {
_maskTintColor = maskTintColor;

_moviePlayerMask.backgroundColor = _maskTintColor;
}

- (void)setMaskAlpha:(CGFloat)maskAlpha {
_maskAlpha = maskAlpha;

_moviePlayerMask.alpha = _maskAlpha;
}

#pragma mark - Video controls

- (void)play {
NSParameterAssert(self.moviePlayer);

[_moviePlayer play];
}

- (void)stop {
NSParameterAssert(self.moviePlayer);

[_moviePlayer stop];
}

- (void)pause {
NSParameterAssert(self.moviePlayer);

[_moviePlayer pause];
}

- (void)restart {
NSParameterAssert(self.moviePlayer);

[_moviePlayer stop];
[_moviePlayer play];
}

@end
Loading

0 comments on commit 2e3f48f

Please sign in to comment.