• 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;





    @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?
 

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