Youtubeview after initializing once not initializing again using youtube api - android

In my android tablet app I have one base activity and that activity has 3fragments
all the fragments has a video playing option and all of them are interlinked, means I can switch from one fragment to the other two fragments
when user clicks the video play option it will open a new activity and play the youtube video.
I'm using youtube api and the video is playing well except for sometime
the video id is generated from the url every time in that youtube activity from the url,I have printed the log and I'm checking whether id is created, and it is created
I've used
youtubeplayerview.initialize(API_KEY, VideoPlayActivity.this);
to initialize the youtubeplayview, and
player.cueVideo(VIDEO_ID);
inside onInitializationSuccess method to add the view to the youtube view
the problem I'm facing is:
if suppose I play the video from fragment A, it played well and good,
now if i go to fragment B from A and again play the video, it will go on loading but will never go inside the onInitializationSuccess method, but if I debug the code, its going well and good.
does the youtube api needs some delay before starting the video?
I don't have any idea why this is happening and what am i missing
Question 2:
Will the youtube api behaviour differ from system to system???
My app has been integrated with facebook and its been done from another pc, and I'm doing youtube from my pc, the final build has to be from the system which integrated facebook,(I know youtube api key doesn't depend on sha1 key which differs from system to system still want to clear my doubt) will it be a problem with youtube at that time?
any help is favourable
Thanks

Related

Play() can only be initiated by a user gesture

I am working on developing an in house API that plays some audio. Essentially, I need to drop some embed code in to my application which provides a play/pause button and plays some audio.
I am using a WebView to embed this code in my application. The player seems to appear in the application although when clicking play, I am getting an error the says Play() can only be initiated by a user gesture.
I understand why I am getting this error and why its important to wait for a user gesture. I'd like to adjust my embed code to meet this functionality but am not clear on what I can do to resolve this error and play the audio. Currently, the audio doesn't automatically begin to play, the user must click the play button in the embed code.
Also, whats a bit odd, is that embedding a YouTube video works fine, I am curious as to why YouTube embeds work while my embed doesn't.
The problem in here is in the code embed, not with react-native. Webview has a property called mediaPlaybackRequiresUserAction wich is true by default, try setting it to false to see if it helps

Multiple YouTube players in activity

I saw many posts about the issue that it is not possible to attach 2 or more Youtube players in one activity.
Its look like youtube api allows only 1 player per activity even if its on fragment.
There is a solution for it?

YouTube Android Player API, can I prevent users from clicking the 'Watch Next' button?

I'm trying to make a kid-safe youtube player (users can't easily watch unapproved content). Using the CHROMELESS style almost gets there, but users can still click the lower banners or 'Watch Next' button that pops on the video. This takes them to the Youtube app where they could browse to any video.
Similar questions that I've found without resolutions:
how to remove bottom overlay ads from custom youtube player Android
Is there any way to disable "Watch Next" block at the end of video using YouTube Android Player API?
Someone in the second thread suggested using "a ViewTreeObserver and hiding that particular view", but I am having trouble getting that to work.
-Hello! Please correct me if i am wrong but this line of code may be helpful to you i think player.setPlayerStyle(PlayerStyle.MINIMAL);
-Try this line this may will sure solve your problem :-
player.setPlayerStyle(PlayerStyle.CHROMELESS);
In case anyone is still stuck with this, here is what worked for me. If you are only playing a single video then cue the video when playing is finished but don't call player.play() unless you want to repeat the video.
if(player.getCurrentTimeMillis()>=player.getDurationMillis())
{
player.cueVideo(CurrentVideoUrl);
}
If you are providing a long list of videos that play one after the other then use an array list
if(player.getCurrentTimeMillis()>=player.getDurationMillis())
{
CurrentVideoIndex++;
CurrentVideoUrl =videosListArray.get(CurrentVideoIndex).getVideoUrl();
player.cueVideo(CurrentVideoUrl);
}

Is there any way to disable "Watch Next" block at the end of video using YouTube Android Player API?

In my app I'm using YouTube Android Player API library from here https://developers.google.com/youtube/android/player/
I have a fragment that extends YouTubePlayerFragment. All works fine, but I need to make some improvements to app.
At the end of some videos I see block "Watch Next" with the link to another video, so I'm curious - does we have a possibility to disable this feature?
I created another solution using WebView, and display video using it - in this case I'm able to turn off any other additional links using "rel=0" in video url, but I want to use native solution.
Any ideas?
Thanks in advance!

Android - Video player from website not playing in WebView

Hi I have a website that has a video player in it, and I want to play that video player insie of my android application. The video player plays great inside of the androids native browser, But when I direct a WebView to go to that same site with the player the video player doesn't show up, All the content around the player shows up. How do I get the video player to play inside of my applications webview?
Webview will not by default allow Javascript which is most likely what your video player is using on the website. You would most likely need to tell your Webview to use Javascript in order for it to at least try to play the video (I say try because I have never done this myself, I usually use a player activity for video).
So by referencing your activies webview object you can do this:
browser = (WebView) findViewById(R.id.webbrowser_wvViewer);
browser.getSettings().setJavaScriptEnabled(true);
Are you sure your video codec is compatible with Android webview ?
Depending on the browser, the required video codec is different.
You can also check this links to debug and see the exact error :
http://www.smartjava.org/content/remote-chrome-debugging-android
Christian,
What version of the Android OS are you testing this on?
In Android version Gingerbread and earlier, your WebView based app must implement the WebChromeClient callback in order to be able to play videos. Here is the documentation for WebChromeClient:
http://developer.android.com/reference/android/webkit/WebChromeClient.html
Specifically, look at the onShowCustomView() and onHideCustomView callbacks. When playing a video the WebView will callback the onShowCustomView() of the WebChromeClient implementation that you provide. The first param in this callback is a view - which is actually the video that you want to display. The app is expected to override this callback and add this view to the application's window. To summarize, your steps will be as follows:
1. Create a WebView in your app, implement the WebChromeClient in your app and register it using WebView.setWebChromeClient(this).
2. Now your app's onShowCustomView will be called when the user selects play on the video.
3. In your app's implementation of onShowCustomView() you can replace the WebView that is currently displayed by the new View. Do the reverse on onHideCustomView callback.
The default implementation for this method is to ignore which is why you are not seeing the video play in your app.

Categories

Resources