I just wanted to know how to disable the youtube icon that comes in the YouTubeStandalonePlayer. Is it possible?
I don't want to take the user to youtube on clicking the icon. Is there any way to disable the youtube icon?
The below is the code how I am playing the the video using the YouTubeStandalonePlayer.
String videoId = getVideoId(cardsInfo.getCard_video_url());
Intent intent = YouTubeStandalonePlayer.createVideoIntent(getActivity(), getResources().getString(R.string.android_key), videoId, 0, true, false);
startActivity(intent);
According to the API, you can't.
But, you can try and use the other (not standalone) classes, which might give you better control as suggested in the docs: There are two ways to play videos. The first option is to place a YouTubePlayerFragment or YouTubePlayerView in your View hierarchy and then use the YouTubePlayer to control video playback in the View. **This gives a fine control of the experience**. If they don't let it, you could atleast have better control of the flow/UI-visibility because you are controling the Activity (in contrast of giving the control to the standalone activity)
Related
In my Android app, I have a webview where there is an embedded YouTube video inside the webview. My app has a native AdMob banner.
I'd like to hide the native admob banner from the app when user plays the video, so the banner does not show while the video is playing and then show the ads again when the video stops playing
The issue is that I do not know how to check if the video was started or stopped.
Any idea how this can be done? Thanks much.
One of the suggestions I think of is to set your AdView's visibility to GONE and also call mAdView.pause() the AdView while the video is playing. This should prevent any additional requests being made to AdMob. Once the video is done playing and you want to show your banner again - you should set the AdView's visibility to VISIBLE and call mAdView.resume()
The communication between webview and native are done through JavascriptInterface. YouTube has built it's API in a similar fashion. you can use the below code to achieve what you want.
To achieve the play/pause functionality via Youtube video you can use YouTube JavaScript Player API.
Example:
<div id="video-placeholder"></div>
<script src="https://www.youtube.com/iframe_api"></script>
When the API is fully loaded, it looks for a global function called onYouTubeIframeAPIReady() which you should define.
Your code should look something like this
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('video-placeholder', {
width: 600,
height: 400,
videoId: 'Xa0Q0J5tOP0',
playerVars: {
color: 'white',
playlist: 'taJ60kskkns,FG0fTKAqZ5g'
},
events: {
onReady: initialize
}
});
}
Just make two buttons and call the needed method on click.
$('#play').on('click', function () {
player.playVideo();
});
$('#pause').on('click', function () {
player.pauseVideo();
});
You can use JavascriptInterface to get the callback inside the native java/kotlin code from WebView.
More details info
Youtube javascript player API with example
JavaScript Interface with example
I am using jquery to show my videos along wither other contents and the admob. It should apply to your case too as you are using webview.
You need to detect the event - onPlayerStateChange. Check this question which shows the code and prerequisties:
Check if YouTube video is playing and run script
why don't you use default videoview to play youtube videos it'll make easier communication between admob bannner and played video apply same logic as mentioned by kasiopeous
I have a WebView with youtube video and 3 tabs. YouTube video is available in 1st Tab while in other 2 tabs there is a content.
Now i want to pause a video when user moves to other tabs. I have tried with
webView.onPause();
and
Class.forName("android.webkit.WebView")
.getMethod("onPause", (Class[]) null)
.invoke(webView, (Object[]) null);
but it is pausing whole WebView and my other 2 tabs are also not responding. How to stop just a video instead of whole WebView process
You can evaluate Javascript from android and stop video playing.
webView.evaluateJavascript(javascript, callBack);
or older versions.
webView.loadUrl(javascript);
check this
https://developer.android.com/reference/android/webkit/WebView.html#evaluateJavascript(java.lang.String,android.webkit.ValueCallback
What type video do you have? iframe or video tag?
On older devices (api <=21) I don't think this is actually possible, but an easy way to retrieve the given idea of a webview's inner controls are to:
Navigate to ../Android/android-sdk/tools/androiduiautomator.bat and open it up.
Make sure your device is connected via an ADB bridge (which it most likely will be)
Take a device screenshot of your screen and hover over the webkit control you want to call onPause which should bring up some information to the right hand side of your screen.
Substitute the id for
Class.ForName("yourId")
and just call a generic click event which should cause an inner effect of pausing. It could also be
Field.getDeclaredField("Id")
but I'm not positive. One of those two should procure a desired result.
You write you have A WebView and 3 tab, do you use from that WebView in All tab?
My Solution is that you use from Another WebView in other tab and if it tabs be selected some data that maybe be needed,be send to them.
In fact this don't solve your question, but i hope that can solve your problem.
I had similar issues with WebViews malfunctioning across my app. I decided to use the complementary function of onPause() (i.e. onResume()) in the same way:
Class.forName("android.webkit.WebView")
.getMethod("onResume", (Class[]) null)
.invoke(webView, (Object[]) null);
So building a new app specifically for the Android TV interface (lollipop leanback) and I'm using the PlaybackOverlayFragment that is provided by the framework which has a PlaybackControlsRow with all the usual controls on it.
The problem is, the default behavior is for the user to have to click the "Play" button to start the video and I want it to start automatically. That part is easy and I have it working but then the Play/Pause icons on the provided control are out of sync (showing play when should be pause) because the item was started outside of the events of clicking on that control.
Documentation is sparse on these framework elements and examining the class I can't find any public method that would allow me to put this control in the proper "mode" or tell it to display the play or pause icon myself.
Anyone with experience with these yet that would know how to do this?
In order to change the state of the button, even after adding your Actions to the Adapter, you'll need to notify the changes to the adapter that has your Action.
mPlayPauseAction.nextIndex(); // next index, if it was pause, it'll be play
notifyChanged(mPlayPauseAction);
// where notifyChanged(Action action) is:
private void notifyChanged(Action action) {
ArrayObjectAdapter adapter = mPrimaryActionsAdapter; // reference to your adapter
if (adapter.indexOf(action) >= 0) {
adapter.notifyArrayItemRangeChanged(adapter.indexOf(action), 1);
return;
}
}
Well, I partially answered my own question.
If I know before the PlaybackControlsRow is created that I want to set it to the pause state (actually, playing state but showing pause button) then if I call setIndex(PlaypauseAction.PAUSE) on the PlayPauseAction before adding it to the controlsrow then it works.
It doesn't appear that I can modify it myself after adding it but that may be something else I'm doing wrong.
I don't want to share youtube videos in my android application.But when i click youtube logo in youtube playe, the link goes to youtube website.
So, How can i hide youtube logo in youtube player.Please suggest some ideas...
Think is i don't want to share youtube videos
I don't know what kind of style you want, but you can use YouTube Player as Activity or Fragment or a View. So you can basically customise your player easily with new YouTubePlayer API. If you want some simple youtube player with fullscreen (no titlebar mode).
You can pick he chromeless style, it doesn't have any controls - it's only a rectangle that plays a video under programmatic control.
You're free to implement your own controls UI outside the player and wire them up through the YouTubePlayer that you get back after initializing a YouTubePlayerView or YouTubePlayerFragment. Keep in mind that, as mentioned in the YouTubePlayerView JavaDoc, "it is not permitted to overlay the [player] view with other views while a video is playing"
Refer below links:
1] https://gist.github.com/TheFinestArtist/5545437
2]https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/YouTubePlayer.PlayerStyle#Enums
Try this way:
ViewGroup tmpVg = youTubeView;
int[] loopLv = new int[]{0,0,4,0,0,3,0,1};
for( int i = 0; i < loopLv.length; i++){
if( i == loopLv.length-1 ){
tmpVg.getChildAt(loopLv[i]).setVisibility( View.GONE );
} else {
tmpVg = (ViewGroup)tmpVg.getChildAt( loopLv[i] );
}
}
your problem will be solved.
I am using a com.google.android.youtube.player.YouTubePlayerView to play my youtube videos, I extend YouTubeBaseActivity. I am having an issue where I call .pause() on the youtube player instance and and set the view VISIBILITY to View.GONE but it keeps buffering after the view has been set to View.GONE and throws and error because it cannot play in a hidden view. I called YouTubePlayer.pause() before hiding the view. Is there another way to stop playback? I want to stop the player and remove the com.google.android.youtube.player.YouTubePlayerView when a button is pressed. Thanks for taking a look.
if(youTubePlayer.isPlaying()){
youTubePlayer.pause();
youTubePlayerView.setVisibility(View.GONE); }
The pause function will will not stop it. You should try to release it for stopping it. Try the following code
youTubePlayer.release();
It's too late to answer - But still, someone might be benefited -
You can set player style in youtube player.
youtubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT) // To set player as youtube provided.
youtubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.MINIMAL) // To set minimal version of the youtube player. In this style you'll not get the player control options.
youtubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.MINIMAL) This line will do the work of Stopping the youtube player playback custom view