Playing only audio and no video in an Android WebView using HTML5

I am currently facing a challenge with a webpage that includes an html5 video and css3 animations. While the web page functions perfectly on an android device's browser, I am experiencing laggy, glitchy, and jumpy animations when using hardware acceleration. On the other hand, software layerType allows for smooth animations but unfortunately, the video does not play (only the audio works) due to lack of support.

In an attempt to resolve this issue, I have experimented with various solutions:

  1. Implementing hardwareAccelerated in the manifest file

  2. Using

    web_view.setLayerType(View.LAYER_TYPE_HARDWARE, null)

  3. Using

    web_view.setLayerType(View.LAYER_TYPE_SOFTWARE, null)

  4. Exploring CrossWalk XWalkView as an alternative solution

    I have also referred to resources such as Android webview slow performance, Android webview slow, Android webview loading data performance very slow, and more for potential solutions.

Upon examining the cordova webView code, I attempted the following adjustments:

        webView.setInitialScale(0)
        webView.isVerticalScrollBarEnabled = false
        // Enable Javascript
        val settings = webView.settings
        settings.javaScriptEnabled = true
        settings.javaScriptCanOpenWindowsAutomatically = true
        settings.layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL

Specifically, the line below significantly improved the animation quality:

        webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null)

However, based on insights from Android webview slow, it appears that html5 video playback may be compromised as a result.

Do you have any recommendations on how to enhance WebView performance while maintaining optimal functionality? The URL performs flawlessly on browsers, so the issue lies within the WebView configuration.

Answer №1

We found a solution by switching between hardware and software acceleration. Initially, when the animations were intense, we used:

webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null)

Then, as the video started playing, we carefully observed and made adjustments to switch to:

webView.setLayerType(View.LAYER_TYPE_HARDWARE, null)

This approach allowed smooth playback of animations with software acceleration while resolving the html5 issue by reverting back to hardware. We also created a javascript interface to control the toggling from the web view to the android app. Hopefully, this solution proves helpful for others facing similar challenges!

Answer №2

Encountering a similar issue? One solution could be to define specific height and width values for the webview.

FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
                "CustomWidth",
                "CustomHeight");

This issue seems to have arisen after an update to Chrome webview version 77.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

HTML counterpart to PHP's include for JavaScript components

I am searching for a Javascript alternative to a method I have been using in PHP. Specifically, I want to streamline the basic setup of my pages: <!DOCTYPE html> <html lang="en"> <head> <meta ch ...

Tips for retrieving nested data objects from a JSON API on the web

Below is the provided API link - I attempted to utilize this jQuery script in order to collect data for each state individually for my project. However, I am facing difficulties accessing the information with the code provided below. $.getJSON('http ...

What is the best way to align a text element to the right and a PNG element to the left within a

I am currently working on setting up a navigation bar with a PNG link in the top left corner, and a text element "menu" in the top right corner. Despite my efforts, I have not been successful in achieving this layout using "float: right;" The code snippet ...

Having trouble dividing an HTML file?

Currently, I am working on creating a very basic web page that is divided into two parts. Each part will have its own HTML file: Welcome.html & Welcome.css: <html> <head> <link rel="stylesheet" type="text/css" href="Welcom ...

What is the method for attaching a div to another div using javascript?

function displayContent(a) { var content = $("#" + a).html().trim(); alert(content); $('#temstoredivid').append( "<div class='maincover' id='maincov1'>" + " <div class='subcover' id='sub ...

Tips on narrowing the left margin of a div when the size of the contained element becomes too large

I am facing a challenge in formatting text on the web that contains equations embedded as SVG images. To address this issue, I have replaced the SVG elements with fixed-sized div in the example provided below. The SVG element is nested within a div specifi ...

Show and hide the div by clicking a button

Looking at the image below, my goal is to display the div under the reply button. (The div consists of a text box and send button) https://i.stack.imgur.com/jnaV4.png The code I have currently functions correctly. However, when clicking any reply button ...

Ways to ensure next/image takes up all available grid space

Is there a way to make the next/image element span from grid 1 through 8? It seems to work fine with the imgtag but not with next/image. .project { display: grid; margin-bottom: 4rem; grid-template-columns: repeat(12, 1fr); align-items: center; } ...

Arrangement of label and input field on my webpage

I am looking to vertically align all the fields one below another. Currently, they are randomly aligned with Bootstrap CSS. The desired layout should look like this: Label1: Textbox1 Label2: Textbox2 Here is the code snippet: Which class should I use to ...

Having trouble setting the background of a div in CSS

How can I apply the background-color: #f8f8f8 class to the step class without interfering with the display of the horizontal lines after 1, 2? What could be causing this issue? .main-progress { text-align: center; position: relative; margin- ...

What is the best way to retrieve the label value of a bar that has been clicked on a HorizontalBarChart using MPAndroidChart

I am currently utilizing the HorizontalBarChart library provided by com.github.PhilJay:MPAndroidChart:v2.2.5. My goal is to retrieve the string values of the bar (label value) that I have clicked on. My chart consists of 7 bars displayed on the yAxis. ch ...

Is it possible to reference the same PHP file in multiple locations?

Currently, I am working on a web development project where I have created a header.html file to store the common header for all my webpages. This header file is located in the parent directory. Within my header.html file, I have included references to bot ...

What is the correct way to use Deviceready in an Ionic application?

I am currently working on a mobile application built with Cordova and Ionic. The default page of the application requires the use of the SQLLite plugin. https://github.com/brodysoft/Cordova-SQLitePlugin The issue I am facing is that the view contains n ...

Assistance requested with Javascript for an HTML dropdown menu

My question involves utilizing two HTML drop down menus. <select> <option value="">Please Select</option> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option ...

Choosing the Angular5 model

I'm currently working with an Angular5 project that has a <select> element bound to an array of customers. Here's the code snippet: <select class="form-control" [ngModel]="record.customer_id" (ngModelChange)="setCustomer($event)" name=" ...

The LESS file could not be located. Attempted to find -

My directory structure is as follows: C:. └───static ├───custom_stuff │ presets.css │ presets.less │ └───index index.less However, I'm encountering an issue where index.less c ...

Issue with Laravel css not being correctly processed by the elixir function in xampp environment

After creating a versioned css file with the following code: elixir(function(mix) { mix.sass('demo.scss') .version('css/demo.css'); }); The file can be found at public/build/demo-34f5737738.css. According to the documentation, ...

Python Application Engine - Streamlining Responses from HTML Control Arrays

In my attempt to use App Engine (Python), I am facing a challenge in sending POST values from a variable array of select controls within an HTML form. Each select control is associated with a text describing what the user is rating. For instance, let&apos ...

There seems to be a glitch with the Flask flash messaging feature, as

My Flask application includes login and register routes where I aim to display flash messages when username passwords are not matched. Specifically, this issue arises in my index and login routes: @app.route('/') @login_required def index(): ...

Tips for concealing overflowing CSS content

How can I prevent CSS content from overflowing? I am trying to display a price tag in the CSS element, but it is protruding out of my card. .content{ content:''; position: absolute; left: 309px; ...