Enable Fullscreen for Youtube videos in WebView
To enable fullscreen mode for YouTube videos in your sketchware project, follow the steps given below.
1. Create a new project in Sketchware.
2. In VIEW area add a WebView webview1.
3. Create a more block extra.
4. In the more block extra, use an add source directly blocks and put codes to define a new WebChromeClient class with name CustomWebClient.
}
public class CustomWebClient extends WebChromeClient {
private View mCustomView;
private WebChromeClient.CustomViewCallback mCustomViewCallback;
protected FrameLayout frame;
// Initially mOriginalOrientation is set to Landscape
private int mOriginalOrientation = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
private int mOriginalSystemUiVisibility;
// Constructor for CustomWebClient
public CustomWebClient() {}
public Bitmap getDefaultVideoPoster() {
if (MainActivity.this == null) {
return null; }
return BitmapFactory.decodeResource(MainActivity.this.getApplicationContext().getResources(), 2130837573); }
public void onShowCustomView(View paramView, WebChromeClient.CustomViewCallback viewCallback) {
if (this.mCustomView != null) {
onHideCustomView();
return; }
this.mCustomView = paramView;
this.mOriginalSystemUiVisibility = MainActivity.this.getWindow().getDecorView().getSystemUiVisibility();
// When CustomView is shown screen orientation changes to mOriginalOrientation (Landscape).
MainActivity.this.setRequestedOrientation(this.mOriginalOrientation);
// After that mOriginalOrientation is set to portrait.
this.mOriginalOrientation = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
this.mCustomViewCallback = viewCallback; ((FrameLayout)MainActivity.this.getWindow().getDecorView()).addView(this.mCustomView, new FrameLayout.LayoutParams(-1, -1)); MainActivity.this.getWindow().getDecorView().setSystemUiVisibility(3846);
}
public void onHideCustomView() {
((FrameLayout)MainActivity.this.getWindow().getDecorView()).removeView(this.mCustomView);
this.mCustomView = null;
MainActivity.this.getWindow().getDecorView().setSystemUiVisibility(this.mOriginalSystemUiVisibility);
// When CustomView is hidden, screen orientation is set to mOriginalOrientation (portrait).
MainActivity.this.setRequestedOrientation(this.mOriginalOrientation);
// After that mOriginalOrientation is set to landscape.
this.mOriginalOrientation = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; this.mCustomViewCallback.onCustomViewHidden();
this.mCustomViewCallback = null;
}
}
{
5. In onCreate event, use add source directly block and put codes to create a new CustomWebClient and set it as the WebChromeClient for the WebView.
webview1.setWebChromeClient(new CustomWebClient());
After that use webview loadUrl block to load youtube.
6. Now add a new event, 'On back button press', in LOGIC area of your app. In this event use if..else.. block. Add Webview goBack block as shown in image below. It should read, if WebView canGoBack then WebView goBack else Finish Activity.
7. Save and Run the project. You can now watch YouTube videos in fullscreen mode in your app.
1. Create a new project in Sketchware.
2. In VIEW area add a WebView webview1.
3. Create a more block extra.
4. In the more block extra, use an add source directly blocks and put codes to define a new WebChromeClient class with name CustomWebClient.
}
public class CustomWebClient extends WebChromeClient {
private View mCustomView;
private WebChromeClient.CustomViewCallback mCustomViewCallback;
protected FrameLayout frame;
// Initially mOriginalOrientation is set to Landscape
private int mOriginalOrientation = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
private int mOriginalSystemUiVisibility;
// Constructor for CustomWebClient
public CustomWebClient() {}
public Bitmap getDefaultVideoPoster() {
if (MainActivity.this == null) {
return null; }
return BitmapFactory.decodeResource(MainActivity.this.getApplicationContext().getResources(), 2130837573); }
public void onShowCustomView(View paramView, WebChromeClient.CustomViewCallback viewCallback) {
if (this.mCustomView != null) {
onHideCustomView();
return; }
this.mCustomView = paramView;
this.mOriginalSystemUiVisibility = MainActivity.this.getWindow().getDecorView().getSystemUiVisibility();
// When CustomView is shown screen orientation changes to mOriginalOrientation (Landscape).
MainActivity.this.setRequestedOrientation(this.mOriginalOrientation);
// After that mOriginalOrientation is set to portrait.
this.mOriginalOrientation = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
this.mCustomViewCallback = viewCallback; ((FrameLayout)MainActivity.this.getWindow().getDecorView()).addView(this.mCustomView, new FrameLayout.LayoutParams(-1, -1)); MainActivity.this.getWindow().getDecorView().setSystemUiVisibility(3846);
}
public void onHideCustomView() {
((FrameLayout)MainActivity.this.getWindow().getDecorView()).removeView(this.mCustomView);
this.mCustomView = null;
MainActivity.this.getWindow().getDecorView().setSystemUiVisibility(this.mOriginalSystemUiVisibility);
// When CustomView is hidden, screen orientation is set to mOriginalOrientation (portrait).
MainActivity.this.setRequestedOrientation(this.mOriginalOrientation);
// After that mOriginalOrientation is set to landscape.
this.mOriginalOrientation = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; this.mCustomViewCallback.onCustomViewHidden();
this.mCustomViewCallback = null;
}
}
{
5. In onCreate event, use add source directly block and put codes to create a new CustomWebClient and set it as the WebChromeClient for the WebView.
webview1.setWebChromeClient(new CustomWebClient());
After that use webview loadUrl block to load youtube.
6. Now add a new event, 'On back button press', in LOGIC area of your app. In this event use if..else.. block. Add Webview goBack block as shown in image below. It should read, if WebView canGoBack then WebView goBack else Finish Activity.
7. Save and Run the project. You can now watch YouTube videos in fullscreen mode in your app.
Sir I have created the quiz app using Json data. but after putting my own Json data the app crashes
ReplyDeleteAnd make video how to automatically change the question in Json quiz app after certain delay of time and also show the timer
Paste this code (oncreate) to not crashes app
Delete(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
Thanks me later!
DeleteI am "mark app studio philippines"
Hey bro can you create how to aeccac all widgets like button or image view in view pager ? Please...
ReplyDeleteHello I can add Videos Ads in app Using Sketchware , I want to show other user how, I will Contact U
ReplyDeletehello i need ur help please i want to creat a chat room app how i can do it? i mean i need to do if user press on image (+) will see pop ask about room name ? if user type name of room,then creat a room
ReplyDeleteHi, I was wondering if it is possible to modify the video player of a webview instead of using the default device player
ReplyDeleteHelp me!
ReplyDeleteI think it works only on main screen!
I'm trying to add it on second screen but it is giving errors!
Kindly tell me that what should i do for running youtube in full screen on second screen!
Thank you!
Hello, I'm having this exact problem right now, did you get it right?
DeleteCopy the same come code and edit the webview1 into whichever webview you want
DeleteJust change the main activity name into current page where webview exists
DeleteIt's not working
ReplyDeleteError "9 problems"
ReplyDeleteError 64 problems
ReplyDeletecan i active full screen option in any video
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteSir plzz help
ReplyDeleteHow to get video view center of screen and how to change background color
Plz plz help me
WebView webview1; webview1=(WebView)findViewById(R.id.webview1); webview1.setBackgroundColor(0x00000000);
DeleteIts working but it is not displaying the ads by google in the website.. Is there any solution for that??
ReplyDeleteThanks you so much bhai (Love you a lot) Thank you so much
ReplyDeleteHow to use in second activity man
ReplyDeleteBro I want to use YouTubePlayerView in Sketchware Pro. I wanna enable full screen button click. I can view the button but I can't go to full screen while clicking on it.. It seems to a dummy button now.
ReplyDeleteWhy click resize or press back is porce. Close app
ReplyDeleteits work but when i try to add this full screen + enable file pic .. just the full screen work
ReplyDeleteHow to create video full screen of other activities without main activity
ReplyDeleteThis code only supports the main activity. Is there any solution for this?
1)
webview1.setWebViewClient(new Browser()); webview1.setWebChromeClient(new MyWebClient());
2)
} final class Browser extends WebViewClient { Browser() {} public boolean shouldOverrideUrlLoading(WebView paramWebView, String paramString) { paramWebView.loadUrl(paramString); return true; } } public class MyWebClient extends WebChromeClient { private View mCustomView; private WebChromeClient.CustomViewCallback mCustomViewCallback; protected FrameLayout mFullscreenContainer; private int mOriginalOrientation = MainActivity.this.getRequestedOrientation(); private int mOriginalSystemUiVisibility; public MyWebClient() {} public Bitmap getDefaultVideoPoster() { if (MainActivity.this == null) { return null; } return BitmapFactory.decodeResource(MainActivity.this.getApplicationContext().getResources(), 2130837573); } public void onHideCustomView() { ((FrameLayout)MainActivity.this.getWindow().getDecorView()).removeView(this.mCustomView); this.mCustomView = null; MainActivity.this.getWindow().getDecorView().setSystemUiVisibility(this.mOriginalSystemUiVisibility); MainActivity.this.setRequestedOrientation(this.mOriginalOrientation); this.mCustomViewCallback.onCustomViewHidden(); this.mCustomViewCallback = null; } public void onShowCustomView(View paramView, WebChromeClient.CustomViewCallback paramCustomViewCallback) { if (this.mCustomView != null) { onHideCustomView(); return; } this.mCustomView = paramView; this.mOriginalSystemUiVisibility = MainActivity.this.getWindow().getDecorView().getSystemUiVisibility(); MainActivity.this.setRequestedOrientation(android.content.pm.ActivityInfo. SCREEN_ORIENTATION_LANDSCAPE); this.mCustomViewCallback = paramCustomViewCallback; ((FrameLayout)MainActivity.this.getWindow().getDecorView()).addView(this.mCustomView, new FrameLayout.LayoutParams(-1, -1)); MainActivity.this.getWindow().getDecorView().setSystemUiVisibility(3846); }
I have been using Sketchware for quite some time, and I always questioned why I couldn't watch YouTube videos in fullscreen mode. I tried to enable it but did not gain. Reading your post has helped me a lot and now I can enjoy fullscreen mode. Dissertation Writing Services
ReplyDelete