You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi all,
So I'm a bit stuck with trying to play a youtube video programmatically. When I use a custom button which calls play() on the YoutubePlayer Object then it invokes the library function which registers the playVideo command (and I do indeed do a cueVideo before that), yet the youtube player doesn't seem to respond in any way. There are no exceptions, warnings or errors. The video cues just fine and I can play it without any issue when I use the Youtube UI directly. Can someone tell me what I'm missing?
Here's how I initialize it
void loadYoutubeFragment() {
// You can assume all null checks and relevant initializations were done
if (webView == null) {
webView = (YouTubePlayerView) (Object) player.findSiblingFragment(R.id.youtube_fragment);
}
try {
YouTubePlayerListener listener = new AbstractYouTubePlayerListener(){};
IFramePlayerOptions options = new IFramePlayerOptions.Builder().controls(0).build();
webView.setEnableAutomaticInitialization(false);
webView.initialize(listener, options);
webView.getYouTubePlayerWhenReady(youTubePlayer -> {
//Add a tracker to get various info from the video
youTubePlayer.addListener(tracker);
video = Optional.of(youTubePlayer);
});
} catch (IllegalStateException e) {
UnisonMobileLog.e("YoutubePlayerFragment", "Exception initialising youtube webview.", e);
}
}
And then (within the same class) the onClick event which should start the video executes this code (and some variations I tried)
public void play() {
video.ifPresent(YouTubePlayer::play);
//.............Also tried this
// webView.getYouTubePlayerWhenReady(youTubePlayer -> {
// youTubePlayer.play();
// });
//............And this (where video in this case is youtubePlayer tyepe)
// if(video != null){
// video.play();
// }
}
And then this is what my XML looks like for the element
Like I said, the video initializes and cues correctly and can be played directly via the UI but I cannot seem to get it to play using the play() method. Please let me know if there's something I'm missing an thanks for and thanks for taking the time to look through this question.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi all,
So I'm a bit stuck with trying to play a youtube video programmatically. When I use a custom button which calls play() on the YoutubePlayer Object then it invokes the library function which registers the playVideo command (and I do indeed do a cueVideo before that), yet the youtube player doesn't seem to respond in any way. There are no exceptions, warnings or errors. The video cues just fine and I can play it without any issue when I use the Youtube UI directly. Can someone tell me what I'm missing?
Here's how I initialize it
And then (within the same class) the onClick event which should start the video executes this code (and some variations I tried)
And then this is what my XML looks like for the element
Like I said, the video initializes and cues correctly and can be played directly via the UI but I cannot seem to get it to play using the play() method. Please let me know if there's something I'm missing an thanks for and thanks for taking the time to look through this question.
Beta Was this translation helpful? Give feedback.
All reactions