Micro blog about Answer to the Ultimate Question of Life, the Universe, and Everything.
  • Home
    • List all categories
    • Sitemap
  • Downloads
    • WebSphere
    • Hitachi902
    • Hospital
    • Kryptonite
    • OCR
    • APK
  • About me
    • Gallery
      • Italy2022
      • Côte d'Azur 2024
    • Curriculum vitae
      • Resume
      • Lebenslauf
    • Social networks
      • Facebook
      • Twitter
      • LinkedIn
      • Xing
      • GitHub
      • Google Maps
      • Sports tracker
    • Adventures planning
  1. You are here:  
  2. Home
  3. Android

Video tag in WebView

Details
Written by: Stanko Milosev
Category: Android
Published: 25 November 2015
Last Updated: 25 November 2015
Hits: 5014

It seems that androids WebView doesn't like video tag.

Here is Android code which worked for me:

        mWebView.setWebViewClient(new WebViewClient() {
            // autoplay when finished loading via javascript injection
            public void onPageFinished(WebView view, String url) {
                mWebView.loadUrl("javascript:(function() { document.getElementsByTagName('video')[0].play(); })()");
            }
        });

        mWebView.setWebChromeClient(new WebChromeClient());

Where WebChromeClient we need to handle javascript methods, and it seems that autoplay in WebView doesn't work.

Also, mWebView is: private WebView mWebView; (I took example of WebView based application)

HTML code looks like:

<video autoplay loop>
	<source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
</video>

Inspect WebView

Details
Written by: Stanko Milosev
Category: Android
Published: 28 August 2015
Last Updated: 04 November 2015
Hits: 4216

To debug your web application in Android in Chrome write:

chrome://inspect/#devices

and click inspect:

Before that in Android code write:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  WebView.setWebContentsDebuggingEnabled(true);
}

Load local file in the WebView

Details
Written by: Stanko Milosev
Category: Android
Published: 25 August 2015
Last Updated: 04 May 2022
Hits: 3865

Here you can see an example of creating WebView for Android. Problem which I had was to load a local file. Simple answer is like this:

mWebView.loadUrl("file:///android_asset/touchEnd/index.html");

Where android_asset is actually assets folder in Android project. To add assets to the Android project, choose view to Android, right click on the app -> New -> Folder -> Assets folder:


Now the whole code can look something like this: 

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mWebView = (WebView) findViewById(R.id.activity_main_webview);
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        mWebView.loadUrl("file:///android_asset/touchEnd/index.html");
    }

Installing Android studio on Ubuntu

Details
Written by: Stanko Milosev
Category: Android
Published: 08 June 2015
Last Updated: 29 June 2015
Hits: 4364

1. You can install Java, just by writing: sudo apt-get install default-jdk in terminal window, or follow these steps: Download Java, in my case I downloaded this one.

2. To install Java, open terminal window, go to the location where you downloaded Java, and write:

tar zxvf jdk-8u45-linux-x64.tar.gz

3. After installing Java write something like:

export JAVA_HOME=/home/myUserName/myDownloadPlace/jdk1.8.0_45

Of course change myUserName/myDownloadPlace.

or write:

sudo gedit /etc/environment

then in environment write:

export JAVA_HOME=/home/myUserName/myDownloadPlace/jdk1.8.0_45

4. Then write:

sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0 lib32stdc++6

5. Finally download Android Studio, extract it, go to bin folder, in my case that is something like:

/home/myUserName/Downloads/android-studio/bin

6. Execute:

./studio.sh 

7. Go to File -> Project Structure -> JDK location box: enter and browse to your Java JDK.

8. Download from here and install Java JRE, and I copied downloaded version to folder /home/myUserName/Android/Sdk/tools/lib/monitor-x86_64/jre

  1. Manually installing factory image on Nexus 5
  2. My list of best applications
  3. Stucked at HBOOT

Page 10 of 11

  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11