Skip to content

Commit

Permalink
Merge pull request #67 from abritopach/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
abritopach authored Nov 19, 2021
2 parents 9973add + 28416d2 commit 167b1e5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public void initialize(final PluginCall call) {

String videoId = call.getString("videoId");
Boolean fullscreen = call.getBoolean("fullscreen");
Log.e(TAG, "[Youtube Player Plugin Native Android]: videoId " + videoId + " | fullscreen: " + fullscreen);
JSObject playerSize = call.getObject("playerSize");
Log.e(TAG, "[Youtube Player Plugin Native Android]: videoId " + videoId + " | fullscreen: " + fullscreen +
" | playerSize: " + playerSize.toString());

Intent intent= new Intent();
intent.setClass(context, YoutubePlayerFragment.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ private void initializeYoutubePlayer(final String videoId) {
if (obj instanceof YouTubePlayerSupportFragment)
youTubePlayerFragment = (YouTubePlayerSupportFragment) obj;

if (youTubePlayerFragment == null)
if (youTubePlayerFragment == null) {
return;
}

youTubePlayerFragment.initialize(BuildConfig.YOUTUBE_API_KEY, new YouTubePlayer.OnInitializedListener() {

Expand All @@ -61,6 +62,7 @@ public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlay
boolean wasRestored) {

if (!wasRestored) {

youTubePlayer = player;

// Set the player style default.
Expand All @@ -72,6 +74,7 @@ public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlay
RxBus.publish(result);

// Specify that we want to handle fullscreen behavior ourselves.

youTubePlayer.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT);
youTubePlayer.setOnFullscreenListener(new YouTubePlayer.OnFullscreenListener() {
@Override
Expand All @@ -84,17 +87,18 @@ public void onFullscreen(boolean b) {
if (fullscreen) {
youTubePlayer.setFullscreen(fullscreen);
}

// Cue the video by videoId.
youTubePlayer.cueVideo(videoId);

}
}

@Override
public void onInitializationFailure(YouTubePlayer.Provider arg0, YouTubeInitializationResult arg1) {
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult error) {

// Print or show error if initialization failed.
Log.e(TAG, "Youtube Player View initialization failed");
Log.e(TAG, "Youtube Player View initialization failed -> error:" + error.toString());

RxBus.publish("Youtube Player View initialization failed");
}
Expand Down
Binary file not shown.
3 changes: 1 addition & 2 deletions ios/Plugin/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public class YoutubePlayer: CAPPlugin {

let options = [
"videoId" : call.getString("videoId") ?? nil,
"width" : call.getInt("width") ?? nil,
"height": call.getInt("height") ?? nil,
"playerSize" : call.getObject("playerSize") ?? nil,
"playerVars": call.getObject("playerVars") ?? nil
] as [String : Any]

Expand Down
15 changes: 7 additions & 8 deletions ios/Plugin/YPViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ public class YPViewController: UIViewController, YouTubePlayerDelegate {
SVProgressHUD.show()
// treat it as a string key dictionary.
let videoId = dictionary["videoId"] as! String
let width = dictionary["width"] as! Int
let height = dictionary["height"] as! Int
// let playerVars = dictionary["playerVars"] as! [String: Any]
let playerSize: [String : Int] = checkSize(width: width, height: height)
var playerSize = dictionary["playerSize"] as! [String: Int]
playerSize = checkSize(size: playerSize)
youtubePlayer = YouTubePlayerView(frame: CGRect(x: 0, y: 0, width: playerSize["width"]!, height: playerSize["height"]!))

youtubePlayer.delegate = self
Expand All @@ -54,15 +53,15 @@ public class YPViewController: UIViewController, YouTubePlayerDelegate {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func checkSize(width: Int, height: Int) -> [String : Int] {
func checkSize(size: [String: Int]) -> [String : Int] {
var playerSize = [
"width" : width ?? self._defaultSizes["width"]!,
"height": height ?? self._defaultSizes["height"]!
"width" : size["width"] ?? self._defaultSizes["width"]!,
"height": size["height"] ?? self._defaultSizes["height"]!
] as [String : Int]
if (playerSize["height"] as! Int > Int(UIScreen.main.bounds.height)) {
if (playerSize["height"]! > Int(UIScreen.main.bounds.height)) {
playerSize["height"] = Int(UIScreen.main.bounds.height);
}
if (playerSize["width"] as! Int > Int(UIScreen.main.bounds.width)) {
if (playerSize["width"]! > Int(UIScreen.main.bounds.width)) {
playerSize["width"] = Int(UIScreen.main.bounds.width);
}
return playerSize;
Expand Down
2 changes: 1 addition & 1 deletion src/definitions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { IPlayerVars, IPlayerState, IPlayerSize } from './web/models/models';

export interface YoutubePlayerPlugin {
initialize(options: {playerId: string, playerSize: IPlayerSize, videoId: string, playerVars?: IPlayerVars,
initialize(options: {playerId?: string, playerSize: IPlayerSize, videoId: string, playerVars?: IPlayerVars,
debug?: boolean}): Promise<{playerReady: boolean, player: string} | undefined>;
destroy(playerId: string): Promise<{result: { method: string, value: boolean }}>;
// Methods playback controls and player settings..
Expand Down

0 comments on commit 167b1e5

Please sign in to comment.