Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
c4d7955
Update the plugin to work on newer Android versions
arctouch-brunowolff Feb 17, 2016
4188449
Update files import config (plugin.xml)
arctouch-brunowolff Feb 17, 2016
9898203
Attempt to change behaviour for IOS so that it calls the result when …
JonSmart Apr 5, 2016
53903bd
Forgot to register the observer.
JonSmart Apr 5, 2016
74f82a5
Update Version number.
JonSmart Apr 5, 2016
f38f5f9
Updating for community
arctouch-brunowolff Apr 5, 2016
3bca68c
Updating readme
arctouch-brunowolff Apr 5, 2016
b08c906
Updating readme
arctouch-brunowolff Apr 5, 2016
ceb5be5
Update AndroidManifest.xml
trakout Apr 12, 2016
f95df3b
Update README.md
trakout Apr 12, 2016
e1c87f5
Update README.md
trakout Apr 12, 2016
659ad47
Add highlight to the config file location
May 2, 2016
09010ef
Version Number change.
JonSmart May 11, 2016
8d1f7bf
Merge commit '659ad479c03540452105c9c3d966c556dda67a74'
JonSmart May 11, 2016
73868d3
Merge commit 'e1c87f534233f56775385317f9b8b74d43420ca6'
JonSmart May 11, 2016
0c68b48
Updated Readme
JonSmart May 11, 2016
aa40a2e
Updated Readme.
JonSmart May 11, 2016
c9a0636
Added support for newer videos which fail with https://code.google.co…
JonSmart May 12, 2016
032e1ce
Move YouTube API dependency to config.xml to reduce the dependency on…
JonSmart May 12, 2016
8195836
Remove un-needed file.
JonSmart May 12, 2016
6e65047
Fixed missing references.
JonSmart May 12, 2016
af25a2c
Fixed missing references.
JonSmart May 12, 2016
c8c2759
no message
JonSmart May 13, 2016
c510cb7
Update Version number.
JonSmart May 13, 2016
47d5671
Adjusted work around for issue: https://code.google.com/p/gdata-issue…
JonSmart May 13, 2016
119d456
Changed Version Number.
JonSmart May 17, 2016
7f54c7c
Changed version check to only load the YouTube app if the broken vers…
JonSmart May 26, 2016
47cf1f0
Better version catch of the offending YouTube App.
JonSmart May 26, 2016
288df2f
Use YouTube Intent with options if available.
JonSmart May 26, 2016
942010a
Use YouTube Intent with options if available.
JonSmart May 26, 2016
967dfa1
Changes made so that the Android Methods call the callback when the V…
JonSmart Dec 14, 2016
2a0cc8f
Updated Version number.
JonSmart Dec 14, 2016
7f06d0e
fix headlines
janpio Apr 17, 2017
8f4dbf6
Added package.json for compatibility with npm
May 23, 2017
e671ef2
test url con franlimndebl
May 23, 2017
8e43b09
Test another package.json
May 23, 2017
67b66b4
Test other package.json
May 23, 2017
789f3f4
indentado con espacios
May 23, 2017
fd70908
Quitado engines
May 23, 2017
04fa1b3
vuelta al de antes
May 23, 2017
e2f395a
Paso versión a 1.0.1
May 23, 2017
9b0d9e5
Merge pull request #3 from franlindebl/master
JonSmart Jun 6, 2017
819fac1
Merge pull request #2 from piotrowski/patch-2
JonSmart Jun 6, 2017
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
44 changes: 35 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,60 @@
#Cordova YoutubeVideoPlayer Plugin
# Cordova YoutubeVideoPlayer Plugin

**Play Youtube Videos in a native Video Player on Android & iOS.**

**This fork works on Android 6, and does not force landscape mode on Android.**


iOS plugin uses **XCDYouTubeKit** by Cédric Luthi:
https://github.com/0xced/XCDYouTubeKit

Android version uses **OpenYoutubeActivity** by Keyes Labs:
Android version (up to 4.4) uses **OpenYoutubeActivity** by Keyes Labs:
https://code.google.com/p/android-youtube-player

##Installation
Android version (5.0+) uses YouTube Android Player API:
https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/YouTubePlayer

Android with YouTube App Version 111662130 requires a workaround to resolve an App issue:
https://code.google.com/p/gdata-issues/issues/detail?id=8244

## Installation

```sh
cordova plugin add https://github.com/Glitchbone/CordovaYoutubeVideoPlayer.git
cordova plugin add https://github.com/JonSmart/CordovaYoutubeVideoPlayer
```

##Usage
## Usage

```javascript
YoutubeVideoPlayer.openVideo('YOUTUBE_VIDEO_ID');
YoutubeVideoPlayer.openVideo('YOUTUBE_VIDEO_ID', function(result) { console.log('YoutubeVideoPlayer result = ' + result); });
```

##Author
For Android 5.0+ you will need to add the following to config.xml

```xml
<preference name="YouTubeDataApiKey" value="[YOUR YOUTUBE API]" />
```
with your own YouTube Key.

For more information: https://developers.google.com/youtube/v3/getting-started

The callback is called when the video window is closed. (Work in Progress - should be working for IOS).

## Author

**Adrien Glitchbone**

+ [https://twitter.com/glitchbone](https://twitter.com/glitchbone)
+ [http://github.com/Glitchbone](http://github.com/Glitchbone)

##License
**d0cz**
+ [http://github.com/d0cz](http://github.com/d0cz)

**trakout**
+ [https://github.com/trakout](https://github.com/trakout)

## License

CordovaYoutubeVideoPlayer is available under the MIT license. See the [LICENSE](LICENSE) file for more information.
XCDYouTubeKit is available under the MIT license.
OpenYoutubeActivity is available under the Apache License 2.0.
OpenYoutubeActivity is available under the Apache License 2.0.
4 changes: 2 additions & 2 deletions config.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.bunkerpalace.YoutubVideoPlayerProject" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<widget id="com.bunkerpalace.YoutubVideoPlayerProject" version="1.0.5" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>YoutubeVideoPlayerProject</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
Sample Cordova You Tube Player App.
</description>
<author email="dev@cordova.apache.org" href="http://cordova.io">
Apache Cordova Team
Expand Down
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "com.bunkerpalace.cordova.YoutubeVideoPlayer",
"version": "1.0.1",
"cordova": {
"id": "com.bunkerpalace.cordova.YoutubeVideoPlayer",
"platforms": [
"android",
"ios"
]
},
"engines": {
"cordovaDependencies": {
}
}
}
3 changes: 2 additions & 1 deletion platforms/android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.keyes.youtube.OpenYouTubePlayerActivity" android:screenOrientation="landscape" />
<activity android:name="com.keyes.youtube.OpenYouTubePlayerActivity" android:screenOrientation="unspecified" />
<activity android:name="com.bunkerpalace.cordova.YouTubeActivity" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize"/>
</application>
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Expand Down
2 changes: 1 addition & 1 deletion platforms/android/assets/www/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ var app = {

},
playVideo: function() {
YoutubeVideoPlayer.openVideo('npjF032TDDQ');
YoutubeVideoPlayer.openVideo('npjF032TDDQ', function(result) { console.log('YoutubeVideoPlayer result = ' + result); });
}
};
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.bunkerpalace.cordova;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayer.Provider;
import com.google.android.youtube.player.YouTubePlayerView;
import com.google.android.youtube.player.YouTubePlayer.PlayerStateChangeListener;

public class YouTubeActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener,
PlayerStateChangeListener {

private static final int RECOVERY_REQUEST = 1;
private YouTubePlayerView youTubeView;
private String videoId;
private String apiKey;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
videoId = intent.getStringExtra("videoId");
apiKey = intent.getStringExtra("YouTubeApiId");
youTubeView = new YouTubePlayerView(this);
youTubeView.initialize(apiKey, this);
setContentView(youTubeView);
}

@Override
public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean wasRestored) {
if (!wasRestored) {
player.loadVideo(videoId);
player.setPlayerStateChangeListener(this);
}
}

@Override
public void onInitializationFailure(Provider provider, YouTubeInitializationResult errorReason) {
if (errorReason.isUserRecoverableError()) {
errorReason.getErrorDialog(this, RECOVERY_REQUEST).show();
} else {
String error = String.format("Error initializing YouTube player", errorReason.toString());
Toast.makeText(this, error, Toast.LENGTH_LONG).show();
}
}

@Override
public void onVideoEnded() {
setResult(RESULT_OK);
finish();
}

@Override
public void onError(
com.google.android.youtube.player.YouTubePlayer.ErrorReason arg0) {
updateLog("onError(): " + arg0.toString());
finish();
}

@Override
public void onAdStarted() {}

@Override
public void onLoaded(String arg0) {}

@Override
public void onLoading() {}

@Override
public void onVideoStarted() {}

private void updateLog(String text){
Log.d("YouTubeActivity", text);
};
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,73 @@
package com.bunkerpalace.cordova;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.ConfigXmlParser;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaPreferences;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;

import com.google.android.youtube.player.YouTubeIntents;
import com.keyes.youtube.OpenYouTubePlayerActivity;
import android.os.Build;
import android.util.Log;

public class YoutubeVideoPlayer extends CordovaPlugin {

private CallbackContext callbackContext;

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {

if(action.equals("openVideo")) {
String url = args.getString(0);
this.openVideo(url, callbackContext);
this.openVideo(url);
this.callbackContext = callbackContext;
return true;
}

}
return false;
}

private void openVideo(String vid, CallbackContext callbackContext) {

Intent intent = new Intent(null, Uri.parse("ytv://"+vid), this.cordova.getActivity(), OpenYouTubePlayerActivity.class);
this.cordova.getActivity().startActivity(intent);

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 242) {
if (resultCode == this.cordova.getActivity().RESULT_OK) {
this.callbackContext.success();
} else {
this.callbackContext.error("Error");
}
}
}

private void openVideo(String videoId) {
Intent intent = createYoutubeIntent(videoId);
cordova.startActivityForResult(this, intent, 242);
}

private Intent createYoutubeIntent(String videoId) {
if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP){
Intent intent;
Context cordovaContext = cordova.getActivity();
String version = YouTubeIntents.getInstalledYouTubeVersionName(cordovaContext);
if(version.startsWith("11.16") && YouTubeIntents.canResolvePlayVideoIntent(cordovaContext)) {
intent = YouTubeIntents.createPlayVideoIntent(cordovaContext, videoId);
} else {
if(YouTubeIntents.canResolvePlayVideoIntentWithOptions(cordovaContext)){
intent = YouTubeIntents.createPlayVideoIntentWithOptions(cordovaContext, videoId, true, true);
} else {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=" + videoId), cordovaContext, YouTubeActivity.class);
intent.putExtra("videoId", videoId);
ConfigXmlParser parser = new ConfigXmlParser();
parser.parse(cordovaContext);
CordovaPreferences prefs = parser.getPreferences();
intent.putExtra("YouTubeApiId", prefs.getString("YouTubeDataApiKey","YOUTUBE_API_KEY"));
}
}
return intent;
}

return new Intent(null, Uri.parse("ytv://" + videoId), cordova.getActivity(), OpenYouTubePlayerActivity.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#import <Cordova/CDV.h>
#import "XCDYouTubeVideoPlayerViewController.h"

@interface YoutubeVideoPlayer : CDVPlugin
@interface YoutubeVideoPlayer : CDVPlugin {
NSString* _eventsCallbackId;
}

- (void)openVideo:(CDVInvokedUrlCommand*)command;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,39 @@ - (void)openVideo:(CDVInvokedUrlCommand*)command
if (videoID != nil) {

XCDYouTubeVideoPlayerViewController *videoPlayerViewController = [[XCDYouTubeVideoPlayerViewController alloc] initWithVideoIdentifier:videoID];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerPlaybackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:videoPlayerViewController.moviePlayer];

[self.viewController presentMoviePlayerViewControllerAnimated:videoPlayerViewController];

pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];

} else {

pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Missing videoID Argument"];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];

}

[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
_eventsCallbackId = command.callbackId;
}

- (void) moviePlayerPlaybackDidFinish:(NSNotification *)notification
{
CDVPluginResult* pluginResult = nil;
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];


[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:notification.object];
MPMovieFinishReason finishReason = [notification.userInfo[MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue];
if (finishReason == MPMovieFinishReasonPlaybackError)
{
NSError *error = notification.userInfo[XCDMoviePlayerPlaybackDidFinishErrorUserInfoKey];
// Handle error
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Playback Error"];
}

[self.commandDelegate sendPluginResult:pluginResult callbackId:_eventsCallbackId];

}

@end
2 changes: 1 addition & 1 deletion platforms/ios/www/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ var app = {

},
playVideo: function() {
YoutubeVideoPlayer.openVideo('npjF032TDDQ');
YoutubeVideoPlayer.openVideo('npjF032TDDQ', function(result) { console.log('YoutubeVideoPlayer result = ' + result); });
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ cordova.define("com.bunkerpalace.cordova.YoutubeVideoPlayer.YoutubeVideoPlayer",

function YoutubeVideoPlayer() {}

YoutubeVideoPlayer.prototype.openVideo = function(YTid) {
YoutubeVideoPlayer.prototype.openVideo = function(YTid, callback) {
exec(function(result) {
console.log(result);
if(callback){
callback('closed');
}
},
function(error) {
console.log(error);
if(callback){
callback('error');
}
},
"YoutubeVideoPlayer",
"openVideo",
Expand Down
Loading