3

有没有办法在我的 Android 应用程序中本地播放 Twitch 流视频?我在互联网上找不到任何有关此的信息。

这就是我目前在 WebView (twitch.html) 中打开 twitch 视频的方式:

<a href="https://twitch.tv/'+element.channel.name+'/embed"> ...

但是,当我将设备从垂直视图更改为水平视图时,这会导致一些错误。然后将播放视频声音而不显示视频,等等。

我正在考虑一个解决方法,如果您可以调用它并由 Android 用户在应用程序浏览器中单独打开 twitch-channel,但是如何在我的代码中添加此异常?这是在我的 MainActivity.java 中:

private class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (Uri.parse(url).getHost().equals("www.example.com")) {
            // This is my web site, so do not override; let my WebView load the page
            return false;
        }
        // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        startActivity(intent);
        return true;
    }
}

它来自官方的 Android 开发者页面,并防止在另一个浏览器应用程序中打开链接。我怎么能为“twitch.tv”添加一个例外?

4

1 回答 1

0

我显示视频的方式是使用这个:

    String url = "http://twitch.tv/PUT CHANNEL HERE/embed";
    WebView mWebView;
    mWebView = (WebView) findViewById(R.id.webview1);
    mWebView.setWebChromeClient(new WebChromeClient());
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);
    mWebView.loadUrl(url);

和我的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:weightSum="1">
        <WebView
            android:id="@+id/webview1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
</LinearLayout>
于 2016-01-13T04:04:11.263 回答