Skip to content

Update for compatability with Phonegap 3.0 CLI #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions CDVVideo.js

This file was deleted.

17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -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()`.
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()`.
36 changes: 36 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>

<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="CDVVideo"
version="3.0.1">
<name>CDVVideo</name>
<description>This plugin allows you to play videos.</description>
<license>MIT</license>
<keywords>cordova,video,videos,movies</keywords>

<js-module src="www/CDVVideo.js" name="CDVVideo">
<clobbers target="plugins.CDVVideo" />
</js-module>

<!-- android -->
<platform name="android">
</platform>

<!-- ios -->
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="CDVVideo">
<param name="ios-package" value="CDVVideo"/>
</feature>
</config-file>

<source-file src="src/ios/CDVVideo.m" />
<source-file src="src/ios/MovieViewController.m" />

<header-file src="src/ios/CDVVideo.h" />
<header-file src="src/ios/MovieViewController.h" />

<framework src="MediaPlayer.framework" />
</platform>

</plugin>
3 changes: 2 additions & 1 deletion CDVVideo.h → src/ios/CDVVideo.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// CDVVideo.h
//
//
// Updated by Tom Krones 2013-09-30.
// Created by Peter Robinett on 2012-10-15.
//
//
Expand All @@ -14,6 +15,6 @@
NSString *movie;
}

- (void)play:(NSMutableArray *)arguments withDict:(NSMutableDictionary *)options;
- (void) play:(CDVInvokedUrlCommand*)command;

@end
17 changes: 9 additions & 8 deletions CDVVideo.m → src/ios/CDVVideo.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// CDVVideo.m
//
//
// Updated by Tom Krones 2013-09-30.
// Created by Peter Robinett on 2012-10-15.
//
//
Expand All @@ -13,10 +14,10 @@
#import <Cordova/CDV.h>

@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]) {
Expand Down Expand Up @@ -47,14 +48,14 @@ - (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]];

}

- (void)dealloc {
[player release];
[movie release];
[super dealloc];
//[player release];
//[movie release];
//[super dealloc];
}

@end
1 change: 1 addition & 0 deletions MovieViewController.h → src/ios/MovieViewController.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion MovieViewController.m → src/ios/MovieViewController.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,7 +15,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;
}
Expand Down
16 changes: 16 additions & 0 deletions www/CDVVideo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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);
};
module.exports = new CDVVideo();