-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
remcob00
committed
Dec 29, 2012
1 parent
7bb3bb0
commit aa09b2d
Showing
2 changed files
with
65 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,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(); | ||
} |
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,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); | ||
} | ||
|
||
} |