question

35153060 avatar image
0 Votes"
35153060 asked RobCaplan edited

xamarin.android webview fullscreen video

Hey everyone! I've just started making an app which mostly works as webview but a strange thing is that android's webview can't play videos fullscreen which is strange since it's a very basic function in my opinion. I've done some googling but all the workarounds include writing your own custom method to go fullscreen which is baffling and I am curious if there's a way to implement it in an easier way? If not, please guide me through the whole process of writing this method ot refer to guides or tutorials which could help me with this task. I know I probably bit a bit more than I can chew but I really wanna make this app happen.

dotnet-xamarin
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, Android WebView doesn't realize the requirement of full-screen playback. To achieve this function, we need to create custom playbacks for it. Try to create a custom WebChromeClient class to rewrite the OnShowCustomView and OnHideCustomView methods. You could search with the keyword as [Android] WebView that can play video in full screen to check the related documentation.

Similar issues:
https://stackoverflow.com/questions/28203163/making-an-embed-video-full-screen-in-android-webview
https://stackoverflow.com/questions/50101902/webview-and-iframe-video-full-screen-issue

0 Votes 0 ·

Yeah, thanks. I did it. It looks like this:

 public class FullScreenClient : WebChromeClient
         {
             readonly FrameLayout.LayoutParams matchParentLayout = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent,
                                                                                                              ViewGroup.LayoutParams.MatchParent);
             readonly ViewGroup content;
             readonly ViewGroup parent;
             View customView;
               
             public FullScreenClient(ViewGroup parent, ViewGroup content)
             {
                 this.parent = parent;
                 this.content = content;
                    
             }
    
                
             public override void OnShowCustomView(View view, ICustomViewCallback callback)
             {
                 customView = view;
                 view.LayoutParameters = matchParentLayout;
                 parent.AddView(view);
                 content.Visibility = ViewStates.Gone;
                 MainActivity hideBar = (MainActivity)Platform.CurrentActivity;
                 hideBar.Window.AddFlags(WindowManagerFlags.Fullscreen);
    
                  
             }
1 Vote 1 ·

Congrats! And thanks for sharing the code.

0 Votes 0 ·

0 Answers