Skip to content

Commit

Permalink
First version
Browse files Browse the repository at this point in the history
  • Loading branch information
remcob00 committed Dec 29, 2012
1 parent 7bb3bb0 commit aa09b2d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
23 changes: 23 additions & 0 deletions assets/www/youtube.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
*
* Cordova / Phonegap YouTube Embed API Plugin
* Remco Beugels (RemcoB00) 2012
*
*/

var YouTube = function() {};

YouTube.prototype.show = function(content, success, fail) {
return cordova.exec( function(args) {
success(args);
}, function(args) {
fail(args);
}, 'YouTube', '', [content]);
};

if(!window.plugins) {
window.plugins = {};
}
if (!window.plugins.youtube) {
window.plugins.youtube = new YouTube();
}
42 changes: 42 additions & 0 deletions src/com/remcob00/plugins/youtube/YouTube.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
*
* Cordova / Phonegap YouTube Embed API Plugin
* Remco Beugels (RemcoB00) 2012
*
*/

package com.remcob00.plugins.youtube;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;

import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;

import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubeStandalonePlayer;

public class YouTube extends Plugin {

@Override
public PluginResult execute(String action, JSONArray args, String callbackId) {
try {
JSONObject jo = args.getJSONObject(0);
doSendIntent(jo.getString("videoid"));
return new PluginResult(PluginResult.Status.OK);
} catch (JSONException e) {
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
}
}

private void doSendIntent(String videoid) {
// API key instructions https://developers.google.com/youtube/android/player/register
Intent youtubeIntent = YouTubeStandalonePlayer.createVideoIntent((Activity) this.cordova, "YOUR_API_KEY", videoid);
this.cordova.startActivityForResult(this, youtubeIntent, 0);
}

}

0 comments on commit aa09b2d

Please sign in to comment.