I have a fragment using a RelativeLayout to hold a webview, and assigned a custom WebChromeClient to it.
When I use the webview to watch Youtube video, it can shows video in a separate view.
However, when I exit from the separate view and go back to webview, the app crashes.
/*Here is part of my WebChromeClient*/
public class CustomWebChromeClient extends WebChromeClient {
/*Function for showing video separate from webview*/
public void onShowCustomView(View view, CustomViewCallback callback) {
frag.mCustomViewCallback = callback;
//mTargetView is used as a video holder for holding the video object
frag.mTargetView.addView(view);
//mCustomView is the video object itself
frag.mCustomView = view;
//hide webview
frag.webview.setVisibility(View.GONE);
//show video holder with its video
frag.mTargetView.setVisibility(View.VISIBLE);
frag.mTargetView.bringToFront();
}
#Override
public void onHideCustomView() {
if (frag.mCustomView == null)
return;
//(I guess) use callback to hide video player widget such as play button and timebar
frag.mCustomViewCallback.onCustomViewHidden();
//remove video object from holder
frag.mTargetView.removeView(frag.mCustomView);
//hide video
frag.mCustomView.setVisibility(View.GONE);
frag.mCustomView = null;
//hide video hodler
frag.mTargetView.setVisibility(View.GONE);
//show webview again
frag.webview.setVisibility(View.VISIBLE);
}
/*... some other codes ...*/
}
Inside my main fragment activity
/*Hide video holder when back key pressed*/
public void onBackPressed() {
/*if is showing video, hide the view*/
if(isShowingVideo){
myWebChromeClient.onHideCustomView();
}
}
Detail situation:
1. in my webview
2. Open Youtube
3. Go to one of the video page
4. Click on video's play icon
5. [Important]While it is still loading(remain black on the video),click fullscreen button it provided.
6. triggered onShowCustomView function, and then a fullscreen video is showing(hide webview and show video view only)
7. some seconds of video play
8. press back key, and triggered onHideCustomView.(hide video view and show webview only)
9. webview's video has resize and about 1~2 seconds, the app crashed and get some error messages.
Error message:
Report WebCore crash to the ErrorReportUtils at:
Thu Dec 11 17:37:11
Fatal signal 11 (SIGSEGV) at 0x000030de (code=0), thread 12526 (WebViewCoreThre)
[unnamed-12510-1] updateTexImage: SurfaceTexture is not attached to an OpenGL ES context
What have I discovered:
1. without using "mCustomViewCallback.onCustomViewHidden();" inside onHideCustomView(), app won't crash,
but video player widget created by mCustomView(the video object) still exists.
2. In situation 5, if I wait until video content shows, then click fullscreen button, app works perfectly after situation 6~8.
Related
I'm currently working on an Ionic/Angular app and I have problems with the video on android.
Everything works fine with ios and web browsers it's just Android.
I'll explain briefly how it is supposed to work. (The app is supposed to help with sports exercises)
I have a preview that can be clicked to show the video demo before doing the exercise. When you click on it plays the video, if you click again it pauses the video. Everything works fine for every platform.
Under the preview, you have a button that activates a function to start the video and reset it to 0
And the exercise start.
The function to start when clicking on the button :
onClickStartButton() {
this.isExerciseStarted = true;
this.exercise.sessionExerciseNumber = this._exerciseIndex;
this.overviewsService.setExercise(this.exercise);
if (this.video.nativeElement) {
(<HTMLVideoElement>this.video.nativeElement).pause();
(<HTMLVideoElement>this.video.nativeElement).currentTime = 0;
(<HTMLVideoElement>this.video.nativeElement).play();
this.isVideoPlaying = false;
}
}
I tried to set a timeout on the if statement to see if the pause() or play() started before the video was fully loaded (i stopped testing after a 3 second timeout) but it doesn't seem to come from there
Here is the HTML of the video being loaded
<video class="ion-no-margin" #video
*ngIf="exercise?.video" playsinline loop preload="metadata"
[ngClass]="{'preview-video': !isExerciseStarted}" tappable (click)="onTapToggleVideo()"
[poster]="exercise.thumbnail">
I have no idea WHY it does not work just for Android.
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.
Android onShowCustomView view disappear of the app then visible again after video finish load.
I'm developing a mobie application, that load source from webservice with Youtube & Google plus my return json back to my webview, then I use html5 video, jwplayer, Youtube depends on my resources,
after show video I got an issue as my topic question:
#Override
public void onShowCustomView(View view, CustomViewCallback callback) {
Log.d(log_tag, "Full screen use!");
mCustomViewCallback = callback;
onum = getResources().getConfiguration().orientation;
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
//mTargetView.addView(view); // it's not ready yet
mCustomView = view;
mTargetView.setVisibility(View.VISIBLE); // visible it first
mTargetView.addView(view); // IF I TOOK THIS LINE OUT IT WONT DISAPPEAR BUT VIDEO CANT PLAY
//mContentView.setVisibility(View.GONE);
mTargetView.bringToFront();
is_fullscreen = true;
}
I notice mTargetView.addView(view); make app screen looks exit to the main desktop, 1-2 minutes after video could play then it showup again with my fullscreen video
Thanks in advance for any help
I'm currently working in my Android app. and so far I got to the point where I need my app. to view some videos for the user
initially I thought of storing my videos in my server (currently is local but might move it later) and then I did not find a way how to do it so I choose to load it from a YouTube channel I made it for that purpose "I thought It'd look more porf." any way!!!
So far I run my app. in my phone coz I read that Emulator is not capable of running videos. It runs in my phone but with some issues.
1- I have to pause the video ASA the video layout pops up and wait for the video to buffer or something like that otherwise I got error msg "this video can't be played"
2- later when it loads it starts by it self even I did not press the start button.
3- the video is taking the top half of the screen leaving the bottom have a in White space with gap between the two halves.
4- the video is not clear as I can view it in my laptop or in YouTube app.
here is my .java code
public class video extends Activity {
String SrcPath = "rtsp://v8.cache3.c.youtube.com/CjYLENy73wIaLQltaP8vg4qMsBMYDSANFEIJbXYtZ29vZ2xlSARSBXdhdGNoYOL6qv2DoMPrUAw=/0/0/0/video.3gp";
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video1);
VideoView myVideoView = (VideoView)findViewById(R.id.vview);
myVideoView.setVideoURI(Uri.parse(SrcPath));
myVideoView.setMediaController(new MediaController(this));
myVideoView.requestFocus();
myVideoView.start();
}}
I really want some helps from you ppl.
any help is appreciated dudes.
Well if you want to play video only during a button press. There are two approaches
1) Remove myVideoView.start(); form the code ,i think it will stop playing of video on load
2)Next approach is do not set default MediaControllerfor video view
you can create custom play button for playing video and give myVideoView.start(); inside it's onclick
Button play = (Button) findViewById(R.id.btnPlay);
play .setOnClickListener(this);
Button pause = (Button) findViewById(R.id.btnPause);
pause .setOnClickListener(this);
Button stop = (Button) findViewById(R.id.btnStop);
stop .setOnClickListener(this);
public void onClick(View v) {
switch(v.getId()){
case R.id.btnPlay:
myVideoView.start();
/* the instruccions of the button */
break;
case R.id.btnPause:
/* the instruccions of the button */
break;
case R.id.btnStop:
myVideoView.stop();
/* the instruccions of the button */
break;
}
}
And the thing about clarity of video you are playing rtsp link which got low quality video eve you can see in link itselp you can see .3gp extension which is low quality
If you want to improve the quality . Have an eye on this
YouTube api
REFER
I use WebView in a dialog and at the first launch it takes up to 1 second to render very simple content. The content is set from code as a String (no loading from network). At the beginning for a while I see empty dialog and then the content appears. How to set a callback for the moment when WebView is ready to be displayed and then call show on an AlertDialogBuilder? I have tried WebViewClient.onPageFinished, WebViewClient.PictureListener.onNewPicture, WebChromeClient.onProgressChanged (==100) with no effect.
webViewInstance.setPictureListener(new PictureListener() {
#Override
public void onNewPicture(WebView view, Picture picture) {
// the code goes here
}
});