android - 在 Android 应用程序中播放 Twitch.Tv 视频? (Android Studio 开发)

标签 android webview android-webview twitch video-embedding

有什么方法可以在我的 Android 应用程序中本地播放 Twitch 流视频吗?我在 Internet 上找不到有关此的任何信息。

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

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

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

我在考虑一个解决方法,如果你可以调用它并由 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”添加异常(exception)?

最佳答案

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

    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>

关于android - 在 Android 应用程序中播放 Twitch.Tv 视频? (Android Studio 开发),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30313933/

相关文章:

java - 在 HttpURLConnection 中,为什么 JSONObject 作为 Params 不起作用,但 String 作为 Params 起作用

java - 运行配置缺少参数选项卡

java - 如何在UI线程之外进行UI操作呢?

android - 处理让我们在 Android M 及更早版本的 WebView 中加密新证书

android - Jellybean/ICS Android HTTP Post 方法 + WebView.RestoreState

android - 错误膨胀类 android.webkit.WebView 在生产中偶尔发生

android - 在 WebView 上设置 loadURLTImeOutValue

android - 为什么 "plus"在 Android 中引用名称中为 ID 资源签名

android - 在 Android 中动态更改 MenuItem?

安卓 WebView : How to scroll the whole activity layout