From a33220823eee73c6a025f877edc031bc4aa2b2ff Mon Sep 17 00:00:00 2001 From: wootwoot1234 Date: Mon, 30 Sep 2013 09:09:45 -0700 Subject: [PATCH 01/10] Phonegap 3.0 compatability (new plugin format and ARC compatible) I've made the plugin compatible with phonegap 3.0 BUT I also tweaked the plugin to work with files on iOS the way I was storing them. Go ahead and try the plugin and see what if it works for you. You can also just compare the CDVVideo.m file with the original to see what I changed and change it back. Discaimer: I'm not a seasoned objective c programer so use this at your own risk and please correct me where I made mistakes. --- plugin.xml | 35 +++++++++++++++++++ CDVVideo.h => src/ios/CDVVideo.h | 2 +- CDVVideo.m => src/ios/CDVVideo.m | 29 ++++++++------- .../ios/MovieViewController.h | 0 .../ios/MovieViewController.m | 2 +- CDVVideo.js => www/CDVVideo.js | 0 6 files changed, 54 insertions(+), 14 deletions(-) create mode 100644 plugin.xml rename CDVVideo.h => src/ios/CDVVideo.h (73%) mode change 100644 => 100755 rename CDVVideo.m => src/ios/CDVVideo.m (62%) mode change 100644 => 100755 rename MovieViewController.h => src/ios/MovieViewController.h (100%) mode change 100644 => 100755 rename MovieViewController.m => src/ios/MovieViewController.m (88%) mode change 100644 => 100755 rename CDVVideo.js => www/CDVVideo.js (100%) mode change 100644 => 100755 diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..ac65ffd --- /dev/null +++ b/plugin.xml @@ -0,0 +1,35 @@ + + + + CDVVideo + This plugin allows you to post usage information to your Google Analytics account. + MIT + cordova,google,analytics + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CDVVideo.h b/src/ios/CDVVideo.h old mode 100644 new mode 100755 similarity index 73% rename from CDVVideo.h rename to src/ios/CDVVideo.h index c16baea..6ebb798 --- a/CDVVideo.h +++ b/src/ios/CDVVideo.h @@ -14,6 +14,6 @@ NSString *movie; } -- (void)play:(NSMutableArray *)arguments withDict:(NSMutableDictionary *)options; +- (void) play:(CDVInvokedUrlCommand*)command; @end \ No newline at end of file diff --git a/CDVVideo.m b/src/ios/CDVVideo.m old mode 100644 new mode 100755 similarity index 62% rename from CDVVideo.m rename to src/ios/CDVVideo.m index 7d57868..2600dc0 --- a/CDVVideo.m +++ b/src/ios/CDVVideo.m @@ -13,10 +13,10 @@ #import @implementation CDVVideo - -- (void)play:(NSMutableArray *)arguments withDict:(NSMutableDictionary *)options { - movie = [arguments objectAtIndex:1]; - NSString *orient = [arguments objectAtIndex:2]; +- (void) play:(CDVInvokedUrlCommand*)command +{ + movie = [command.arguments objectAtIndex:0]; + NSString *orient = [command.arguments objectAtIndex:1]; NSRange range = [movie rangeOfString:@"http"]; if(range.length > 0) { if ([@"YES" isEqualToString:orient]) { @@ -26,11 +26,16 @@ - (void)play:(NSMutableArray *)arguments withDict:(NSMutableDictionary *)options } } 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]; + //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]; + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); + NSString *soundFilePath = [paths objectAtIndex:0]; + NSURL *fileURL = [NSURL fileURLWithPath:[soundFilePath stringByAppendingPathComponent:movie]]; + //NSURL *fileURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:movie]]; + //NSLog(soundFilePath); if ([@"YES" isEqualToString:orient]) { player = [[MovieViewController alloc] initWithContentURL:fileURL andOrientation:YES]; } else { @@ -52,9 +57,9 @@ - (void)MovieDidFinish:(NSNotification *)notification { } - (void)dealloc { - [player release]; - [movie release]; - [super dealloc]; + //[player release]; + //[movie release]; + //[super dealloc]; } @end diff --git a/MovieViewController.h b/src/ios/MovieViewController.h old mode 100644 new mode 100755 similarity index 100% rename from MovieViewController.h rename to src/ios/MovieViewController.h diff --git a/MovieViewController.m b/src/ios/MovieViewController.m old mode 100644 new mode 100755 similarity index 88% rename from MovieViewController.m rename to src/ios/MovieViewController.m index 438dadb..c695e43 --- a/MovieViewController.m +++ b/src/ios/MovieViewController.m @@ -14,7 +14,7 @@ @implementation MovieViewController - (id)initWithContentURL:(NSURL *)url andOrientation:(BOOL)orientation { - MovieViewController *o = [[[[self class] alloc] initWithContentURL:url] autorelease]; + MovieViewController *o = [[[self class] alloc] initWithContentURL:url]; o.orientation = orientation; return o; } diff --git a/CDVVideo.js b/www/CDVVideo.js old mode 100644 new mode 100755 similarity index 100% rename from CDVVideo.js rename to www/CDVVideo.js From fc8acea9f36d0fb4dad71712cb2c569fce8f3fa0 Mon Sep 17 00:00:00 2001 From: wootwoot1234 Date: Mon, 30 Sep 2013 09:25:16 -0700 Subject: [PATCH 02/10] Updated README --- README.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e65de0f..64c85b4 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,16 @@ # CDVVideo -CDVVideo is a Cordova 1.7+ plugin for iOS that allows playing video (local or remote) via a native video player. It is essentially a port of eiffelqiu's [phonegape-videoplayer-plugin](phonegap-videoplayer-plugin). +NOTE: I've edited this plugin to work with the way I was storing files on iOS. If you want to go back to how it was, just compare the CVVideo.m files from this fork and bubblefoundry's [https://github.com/bubblefoundry/CDVVideo](CDVVideo Cordova +1.7). + +## Description +CDVVideo is a Cordova/Phonegap 3.0+ plugin for iOS that allows playing video (local or remote) via a native video player. + +## History +This is a port of eiffelqiu's [https://github.com/eiffelqiu/phonegap-videoplayer-plugin](phonegap-videoplayer-plugin) done by bubblefoundry [https://github.com/bubblefoundry/CDVVideo](CDVVideo Cordova +1.7) which was then edited by wootwoot1234 to work with the Cordova/Phonegap 3.0+ command line interface. ## Installation -1. Drop the `.h` and `.m` files into the Cordova `Plugins` folder. Use the default options. -2. Add an entry to the `Plugins` dictionary in `Cordova.plist`. The key should be `CDVVideo` and the value must be `CDVVideo`. -3. Add the `CDVVideo.js` file somewhere under your `www` directory and include it in your `index.html` file. -4. Play a video by calling `CDVVideo.play(video, portrait)`, where `video` is the URL or filename you wish to play and `portrait` is a string that is either `YES` or `NO`, indicating whether portrait or landscape orientation should be used. -5. _Optional:_ Change or overwrite `CDVVideo.finished(video)` to handle when a video finishes playing. `video` corresponds to the video that you passed to `CDVVideo.play()`. \ No newline at end of file +1. Using Phonegap CLI, in terminal navigate to your projects root directory. +2. run `phonegap local plugin add https://github.com/wootwoot1234/CDVVideo.git` +3. Play a video by calling `window.plugins.CDVVideo.play(video, portrait)`, where `video` is the URL or filename you wish to play and `portrait` is a string that is either `YES` or `NO`, indicating whether portrait or landscape orientation should be used. +4. _Optional:_ Change or overwrite `window.plugins.CDVVideo.finished(video)` to handle when a video finishes playing. `video` corresponds to the video that you passed to `window.plugins.CDVVideo.play()`. \ No newline at end of file From 044d4c05b8a50e3310687cb2163b51515b132ffe Mon Sep 17 00:00:00 2001 From: wootwoot1234 Date: Mon, 30 Sep 2013 09:53:31 -0700 Subject: [PATCH 03/10] Updated js file and added credit for edit --- src/ios/CDVVideo.h | 1 + src/ios/CDVVideo.m | 1 + src/ios/MovieViewController.h | 1 + src/ios/MovieViewController.m | 1 + www/CDVVideo.js | 22 +++++++++++++++------- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/ios/CDVVideo.h b/src/ios/CDVVideo.h index 6ebb798..761ae02 100755 --- a/src/ios/CDVVideo.h +++ b/src/ios/CDVVideo.h @@ -2,6 +2,7 @@ // CDVVideo.h // // +// Updated by Tom Krones 2013-09-30. // Created by Peter Robinett on 2012-10-15. // // diff --git a/src/ios/CDVVideo.m b/src/ios/CDVVideo.m index 2600dc0..858d51e 100755 --- a/src/ios/CDVVideo.m +++ b/src/ios/CDVVideo.m @@ -2,6 +2,7 @@ // CDVVideo.m // // +// Updated by Tom Krones 2013-09-30. // Created by Peter Robinett on 2012-10-15. // // diff --git a/src/ios/MovieViewController.h b/src/ios/MovieViewController.h index bc5fa5e..cd4921b 100755 --- a/src/ios/MovieViewController.h +++ b/src/ios/MovieViewController.h @@ -2,6 +2,7 @@ // MovieViewController.h // // +// Updated by Tom Krones 2013-09-30. // Created by Peter Robinett on 2012-10-15. // // Based on phonegap-videoplayer-plugin by eiffel on 2011-11-09 diff --git a/src/ios/MovieViewController.m b/src/ios/MovieViewController.m index c695e43..39e4fa9 100755 --- a/src/ios/MovieViewController.m +++ b/src/ios/MovieViewController.m @@ -2,6 +2,7 @@ // MovieViewController.m // // +// Updated by Tom Krones 2013-09-30. // Created by Peter Robinett on 2012-10-15. // // Based on phonegap-videoplayer-plugin by eiffel on 2011-11-09 diff --git a/www/CDVVideo.js b/www/CDVVideo.js index 18e21ee..7e73508 100755 --- a/www/CDVVideo.js +++ b/www/CDVVideo.js @@ -1,8 +1,16 @@ -var CDVVideo = { - play: function play(video, portrait, callback, errback) { - cordova.exec(callback, errback, 'CDVVideo', 'play', [video, portrait]); - }, - finished: function finished(video) { +var exec = require("cordova/exec"); + +function CDVVideo() +{ + this.available = false; +} + +CDVVideo.prototype.play = function(video, portrait, callback, errback) +{ + exec(callback, errback, 'CDVVideo', 'play', [video, portrait]); +}; +CDVVideo.prototype.finished = function(video) +{ console.log("finished playing video " + video); - } -} \ No newline at end of file +}; +module.exports = new CDVVideo(); \ No newline at end of file From 5239a2f4e3f348741b2f6f24aca1e585004098bc Mon Sep 17 00:00:00 2001 From: wootwoot1234 Date: Mon, 30 Sep 2013 10:10:57 -0700 Subject: [PATCH 04/10] Updated plugin.xml --- plugin.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin.xml b/plugin.xml index ac65ffd..5997d3c 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,11 +2,11 @@ + version="3.0.0"> CDVVideo - This plugin allows you to post usage information to your Google Analytics account. + This plugin allows you to play videos. MIT - cordova,google,analytics + cordova,video,videos,movies From be8249479303283731d901f46935fca4cd47d2e1 Mon Sep 17 00:00:00 2001 From: wootwoot1234 Date: Mon, 30 Sep 2013 14:19:03 -0700 Subject: [PATCH 05/10] Plugin doesn't need to run onload --- plugin.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index 5997d3c..6d77a5e 100644 --- a/plugin.xml +++ b/plugin.xml @@ -21,7 +21,6 @@ - From 23661bbac996a911671bcd0242fedc4c24a2904e Mon Sep 17 00:00:00 2001 From: wootwoot1234 Date: Mon, 30 Sep 2013 17:14:20 -0700 Subject: [PATCH 06/10] removed adobe from id --- plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index 6d77a5e..9ddc661 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,7 +1,7 @@ CDVVideo This plugin allows you to play videos. From 9e5fabfec7b33429581037d17df618e648b84f2f Mon Sep 17 00:00:00 2001 From: wootwoot1234 Date: Fri, 11 Oct 2013 12:44:02 -0700 Subject: [PATCH 07/10] Fixed issue with finished callback --- src/ios/CDVVideo.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ios/CDVVideo.m b/src/ios/CDVVideo.m index 858d51e..b231c73 100755 --- a/src/ios/CDVVideo.m +++ b/src/ios/CDVVideo.m @@ -53,7 +53,7 @@ - (void)MovieDidFinish:(NSNotification *)notification { [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; - [self writeJavascript:[NSString stringWithFormat:@"CDVVideo.finished(\"%@\");", movie]]; + [self writeJavascript:[NSString stringWithFormat:@"window.plugins.CDVVideo.finished(\"%@\");", movie]]; } From 9c52d3b5d244c27f6f720e3d9d6b317e16b39bf4 Mon Sep 17 00:00:00 2001 From: wootwoot1234 Date: Tue, 15 Oct 2013 10:21:23 -0700 Subject: [PATCH 08/10] Removed my custom code --- src/ios/CDVVideo.m | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/ios/CDVVideo.m b/src/ios/CDVVideo.m index b231c73..062eebb 100755 --- a/src/ios/CDVVideo.m +++ b/src/ios/CDVVideo.m @@ -27,16 +27,11 @@ - (void) play:(CDVInvokedUrlCommand*)command } } 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]; - NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); - NSString *soundFilePath = [paths objectAtIndex:0]; - NSURL *fileURL = [NSURL fileURLWithPath:[soundFilePath stringByAppendingPathComponent:movie]]; - //NSURL *fileURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:movie]]; - //NSLog(soundFilePath); + 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 { From 0cdb726101b0d4b89c8d24c7a3a7cf8a5ec4bc08 Mon Sep 17 00:00:00 2001 From: wootwoot1234 Date: Wed, 23 Oct 2013 12:13:30 -0700 Subject: [PATCH 09/10] Added MediaPlayer.framework --- plugin.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin.xml b/plugin.xml index 9ddc661..fab564a 100644 --- a/plugin.xml +++ b/plugin.xml @@ -29,6 +29,8 @@ + + From a2b2e18cb9f524c000e246d016f6a1fb7c9d3024 Mon Sep 17 00:00:00 2001 From: wootwoot1234 Date: Wed, 23 Oct 2013 14:31:08 -0700 Subject: [PATCH 10/10] Changed version from 3.0.0 to 3.0.1 --- plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index fab564a..74aff57 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="3.0.1"> CDVVideo This plugin allows you to play videos. MIT