-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCDVVideo.m
60 lines (52 loc) · 2.07 KB
/
CDVVideo.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// CDVVideo.m
//
//
// Created by Peter Robinett on 2012-10-15.
//
//
#import "CDVVideo.h"
#import "MediaPlayer/MPMoviePlayerViewController.h"
#import "MediaPlayer/MPMoviePlayerController.h"
#import "MovieViewController.h"
#import <Cordova/CDV.h>
@implementation CDVVideo
- (void)play:(NSMutableArray *)arguments withDict:(NSMutableDictionary *)options {
movie = [arguments objectAtIndex:1];
NSString *orient = [arguments objectAtIndex:2];
NSRange range = [movie rangeOfString:@"http"];
if(range.length > 0) {
if ([@"YES" isEqualToString:orient]) {
player = [[MovieViewController alloc] initWithContentURL:[NSURL URLWithString:movie] andOrientation:YES];
} else {
player = [[MovieViewController alloc] initWithContentURL:[NSURL URLWithString:movie] andOrientation:NO];
}
} else {
NSArray *fileNameArr = [movie componentsSeparatedByString:@"."];
NSString *prefix = [fileNameArr objectAtIndex:0];
NSString *suffix = [fileNameArr objectAtIndex:1];
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:prefix ofType:suffix];
NSURL *fileURL = [NSURL fileURLWithPath:soundFilePath];
if ([@"YES" isEqualToString:orient]) {
player = [[MovieViewController alloc] initWithContentURL:fileURL andOrientation:YES];
} else {
player = [[MovieViewController alloc] initWithContentURL:fileURL andOrientation:NO];
}
}
if (player) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MovieDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[self.viewController presentMoviePlayerViewControllerAnimated:player];
}
}
- (void)MovieDidFinish:(NSNotification *)notification {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[self writeJavascript:[NSString stringWithFormat:@"CDVVideo.finished(\"%@\");", movie]];
}
- (void)dealloc {
[player release];
[movie release];
[super dealloc];
}
@end