-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Ekhoo/dev
Bêta EKVideoController
- Loading branch information
Showing
22 changed files
with
1,106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.