In my app I implement the brightcove video player.
I am working on customizing brightcove.
I successfully implemented the play/pause option, and I am trying the same for the rewind option, but to no avail.
Here is my code
BrightcoveVideoView commonVideoView = (BrightcoveVideoView)view.findViewById(R.id.commonVideoViewId);
BrightcoveMediaController mediaController = new BrightcoveMediaController(commonVideoView, R.layout.media_controllers);
How can I solve this issue?
You can use the seekTo method for achieving the same.
brightcoveVideoView.seekTo(value);
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 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
There is a problem in my application,I want to use the seekTo() function with VideoView like this:
videoView.seekTo(time);
videoView.start();
It works well in android 2.2 ,but doesn't work in android 2.3 or higher version...
Some body will tell me why? It troubles me for serval days.
The call to VideoView.start() should be made only after the seek has completed. The call to VideoView.seekTo() initiates a seek but unfortunately VideoView does not support OnSeekCompleteListener needed to notify the seek is actually done.
You can customize VideoView to support OnSeekCompleteListener as shown in my answer to 7990784.
Then you can register to receive onSeekComplete() by calling setOnSeekCompleteListener(). Your implementation of the listener should then call VideoView.start().
Have you tried VideoView class from Vitamio library?
Vitamio
For proper operation of the method seekTo(),the video state should be in PlaybackState.
Checkout the VideoView source here for get more information.
This solution should work.
The problem may be that the mediaplayer inside videoView has not been created.
It's easy to test, by changing the orientation of the device. That's how I tested it.
videoView.setOnPreparedListener(onPreparedListener);
private MediaPlayer.OnPreparedListener onPreparedListener = new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
mp.seekTo(videoPosition);
}
};
By default the mediacontroller for video view appears only for 3 sec. I want it to be there untill the song is playing. I know I have to use this peice of code: -
mediacontrollername.show(0);
But apparently it doesn't seems to be doing its job correctly
What should I do for this?
Just in case anyone searched for this issue and still needs a solution, have a look at this: MediaController 3 Second Issue