有没有一种方法可以在 Android 应用程序(Java)中播放 Twitch 流?

4

我无法在我的安卓应用程序中播放Twitch流。

Twitch只提供嵌入式URL来播放流。

我正在使用此URL:https://player.twitch.tv/?channel=CHANNEL_NAME

我正在使用WebView加载此URL。

mWebview.loadUrl(url);

但这种方法存在一些问题,例如视频往往会自动播放,但最初会卡顿。我需要先按下 暂停,然后再点击 播放 按钮来开始此流。

https://dev.twitch.tv/docs/api/reference#get-streams - Akash Pal
1个回答

1
尝试使用这段代码。
  private WebView mWebview ;

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    getWindow().requestFeature(Window.FEATURE_PROGRESS);
    mWebview  = new WebView(this);

    mWebview.getSettings().setJavaScriptEnabled(true); // enable javascript

    final Activity activity = this;

    mWebview.setWebViewClient(new WebViewClient() {
        @SuppressWarnings("deprecation")
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
        }
        @TargetApi(android.os.Build.VERSION_CODES.M)
        @Override
        public void onReceivedError(WebView view, WebResourceRequest req, WebResourceError rerr) {
            // Redirect to deprecated method, so you can use it in all SDK versions
            onReceivedError(view, rerr.getErrorCode(), rerr.getDescription().toString(), req.getUrl().toString());
        }
    });

    mWebview .loadUrl(url);
    setContentView(mWebview );

}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接