• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

How to play hls/m3u8 streams in webview

darth_daniel

Lurker
Jan 24, 2019
7
0
hi,

I set up a live streaming site and wanted it to be accessible through webview. Unfortunately haven't had much luck as with various code variations I have tried, when i try to play the stream within the webview I keep getting a "The media could not be loaded, either because the server or network failed or because the format is not supported"

My webview script is:

Java:
public class MainActivity extends AppCompatActivity {

    //private WebView webview;
    //private WebView webview;

    //private WebView stream;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if(isNetworkStatusAvialable (getApplicationContext())) {
            Toast.makeText(getApplicationContext(), "internet avialable", Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(getApplicationContext(), "internet is not avialable", Toast.LENGTH_SHORT).show();

        }

        /**
        webview =(WebView)findViewById(R.id.webView);

        webview.setWebViewClient(new WebViewClient());
        webview.getSettings().setJavaScriptEnabled(true);
        webview.getSettings().setDomStorageEnabled(true);
        webview.setOverScrollMode(WebView.OVER_SCROLL_NEVER);
        webview.setWebChromeClient(new WebChromeClient());
        webview.loadUrl("http://192.168.43.140/YouPHPTube/index.php");
        **/


        /**
        myWebView = (WebView) findViewById(R.id.webView);

        // Settings
        WebSettings webSettings = myWebView.getSettings();

        webSettings.setAllowFileAccessFromFileURLs(true);
        webSettings.setAllowUniversalAccessFromFileURLs(true);

        // Set a web view client and a chrome client

    // Load the local HTML file into the webview
        myWebView.loadUrl("http://192.168.43.140/YouPHPTube/index.php");
        myWebView.setWebViewClient(new WebViewClient());
        webSettings.setJavaScriptEnabled(true);

        WebChromeClient MyCustomChromeClient;
        WebView vistaWeb = (WebView) findViewById(R.id.webView);
        vistaWeb.setWebChromeClient(new WebChromeClient());
        //vistaWeb.setWebViewClient(new WebChromeClient());
        vistaWeb.clearCache(true);
        vistaWeb.clearHistory();
        vistaWeb.getSettings().setJavaScriptEnabled(true);
        vistaWeb.getSettings().setDomStorageEnabled(true);
        vistaWeb.loadUrl("http://192.168.43.140/YouPHPTube/index.php");
         **/

        FrameLayout layout = (FrameLayout) findViewById(R.id.web_view_placeholder);

        WebView webView = new WebView(this);

        layout.addView(webView);

        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setUseWideViewPort(false);
        webSettings.setDomStorageEnabled(true);
        webSettings.setSaveFormData(true);
        webSettings.setLoadWithOverviewMode(true);

        final WebChromeClient webChromeClient = new WebChromeClient();
        webView.setWebViewClient(new WebViewClient());
        webView.setWebChromeClient(webChromeClient);
        webView.loadUrl("http://192.168.43.140/YouPHPTube/index.php");



    }

    public static boolean isNetworkStatusAvialable (Context context) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivityManager != null)
        {
            NetworkInfo netInfos = connectivityManager.getActiveNetworkInfo();
            if(netInfos != null)
                if(netInfos.isConnected())
                    return true;
        }
        return false;
    }
}

Is there any way I can get my live stream site's streams to be watchable in webview?
 
Yes I do.

Code:
W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 15928
D/libc-netbsd: getaddrinfo: www.google-analytics.com get result from proxy gai_error = 0
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
D/OpenSSLLib: OpensslErr:Module:12(175:); file:external/boringssl/src/crypto/asn1/asn1_lib.c ;Line:175;Function:ASN1_get_object
D/OpenSSLLib: OpensslErr:Module:12(175:); file:external/boringssl/src/crypto/asn1/asn1_lib.c ;Line:175;Function:ASN1_get_object
I/chromium: [INFO:CONSOLE(39)] "Uncaught TypeError: Cannot read property 'getComponent' of undefined", source: http://192.168.43.140/YouPHPTube/plugin/AD_Overlay/videojs-overlay/videojs-overlay.js (39)
I/chromium: [INFO:CONSOLE(2132)] "A Javascript-error happend. Please tell your admin to clear the folder videos/cache.
     If this doesn't help, attach these infos to a github-pull-request:
     Msg:Uncaught TypeError: Cannot read property 'getComponent' of undefined
     Url: http://192.168.43.140/YouPHPTube/plugin/AD_Overlay/videojs-overlay/videojs-overlay.js, line: 39, Address: /YouPHPTube/index.php", source: http://192.168.43.140/YouPHPTube/index.php (2132)
I/chromium: [INFO:CONSOLE(2)] "jQuery.Deferred exception: videojs is not defined", source: http://192.168.43.140/YouPHPTube/view/js/jquery-3.3.1.min.js (2)
I/chromium: [INFO:CONSOLE(2)] "Uncaught ReferenceError: videojs is not defined", source: http://192.168.43.140/YouPHPTube/view/js/jquery-3.3.1.min.js (2)
D/libc-netbsd: getaddrinfo: stats.g.doubleclick.net get result from proxy gai_error = 0
I/chromium: [INFO:CONSOLE(2132)] "A Javascript-error happend. Please tell your admin to clear the folder videos/cache.
     If this doesn't help, attach these infos to a github-pull-request:
     Msg:Uncaught ReferenceError: videojs is not defined
     Url: http://192.168.43.140/YouPHPTube/view/js/jquery-3.3.1.min.js, line: 2, Address: /YouPHPTube/index.php", source: http://192.168.43.140/YouPHPTube/index.php (2132)
D/OpenSSLLib: OpensslErr:Module:12(175:); file:external/boringssl/src/crypto/asn1/asn1_lib.c ;Line:175;Function:ASN1_get_object
D/OpenSSLLib: OpensslErr:Module:12(175:); file:external/boringssl/src/crypto/asn1/asn1_lib.c ;Line:175;Function:ASN1_get_object
D/libc-netbsd: getaddrinfo: www.google.com get result from proxy gai_error = 0
D/OpenSSLLib: OpensslErr:Module:12(175:); file:external/boringssl/src/crypto/asn1/asn1_lib.c ;Line:175;Function:ASN1_get_object
D/OpenSSLLib: OpensslErr:Module:12(175:); file:external/boringssl/src/crypto/asn1/asn1_lib.c ;Line:175;Function:ASN1_get_object
D/OpenGLRenderer: ProgramCache.generateProgram: 34364981312
D/WebView: loadUrl=http://192.168.43.140/YouPHPTube/plugin/Live/?c=TwendeSmart
W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 15928
E/: appName=cpr.name.videoenabledwebview, acAppName=vStudio.Android.Camera360
    0
I/BufferQueue: [unnamed-15928-0](this:0x8aef7000,id:0,api:0,p:-1,c:-1) BufferQueue core=(15928:cpr.name.videoenabledwebview)
I/BufferQueueConsumer: [unnamed-15928-0](this:0x8aef7000,id:0,api:0,p:-1,c:15928) connect(C): consumer=(15928:cpr.name.videoenabledwebview) controlledByApp=true
    [unnamed-15928-0](this:0x8aef7000,id:0,api:0,p:-1,c:15928) setConsumerName: unnamed-15928-0
I/BufferQueueConsumer: [SurfaceTexture-108-15928-0](this:0x8aef7000,id:0,api:0,p:-1,c:15928) setConsumerName: SurfaceTexture-108-15928-0
D/OpenSSLLib: OpensslErr:Module:12(175:); file:external/boringssl/src/crypto/asn1/asn1_lib.c ;Line:175;Function:ASN1_get_object
I/X509Util: Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
D/OpenSSLLib: OpensslErr:Module:12(175:); file:external/boringssl/src/crypto/asn1/asn1_lib.c ;Line:175;Function:ASN1_get_object
I/chromium: [INFO:CONSOLE(128)] "VIDEOJS:", source: http://192.168.43.140/YouPHPTube/js/video.js/video.js (128)
I/chromium: [INFO:CONSOLE(128)] "VIDEOJS:", source: http://192.168.43.140/YouPHPTube/js/video.js/video.js (128)
I/chromium: [INFO:CONSOLE(128)] "VIDEOJS:", source: http://192.168.43.140/YouPHPTube/js/video.js/video.js (128)
I/chromium: [INFO:CONSOLE(128)] "VIDEOJS:", source: http://192.168.43.140/YouPHPTube/js/video.js/video.js (128)
    [INFO:CONSOLE(128)] "VIDEOJS:", source: http://192.168.43.140/YouPHPTube/js/video.js/video.js (128)
    [INFO:CONSOLE(128)] "VIDEOJS:", source: http://192.168.43.140/YouPHPTube/js/video.js/video.js (128)
I/BufferQueueConsumer: [SurfaceTexture-108-15928-0](this:0x8aef7000,id:0,api:0,p:-1,c:-1) disconnect(C)
I/BufferQueue: [unnamed-15928-1](this:0x8a9b5000,id:1,api:0,p:-1,c:-1) BufferQueue core=(15928:cpr.name.videoenabledwebview)
I/BufferQueueConsumer: [unnamed-15928-1](this:0x8a9b5000,id:1,api:0,p:-1,c:15928) connect(C): consumer=(15928:cpr.name.videoenabledwebview) controlledByApp=true
    [unnamed-15928-1](this:0x8a9b5000,id:1,api:0,p:-1,c:15928) setConsumerName: unnamed-15928-1
    [SurfaceTexture-31-15928-1](this:0x8a9b5000,id:1,api:0,p:-1,c:15928) setConsumerName: SurfaceTexture-31-15928-1
D/OpenSSLLib: OpensslErr:Module:12(175:); file:external/boringssl/src/crypto/asn1/asn1_lib.c ;Line:175;Function:ASN1_get_object
I/chromium: [INFO:CONSOLE(128)] "VIDEOJS:", source: http://192.168.43.140/YouPHPTube/js/video.js/video.js (128)
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones