我无法在我的安卓应用程序中播放Twitch流。
Twitch只提供嵌入式URL来播放流。
我正在使用此URL:https://player.twitch.tv/?channel=CHANNEL_NAME
我正在使用WebView加载此URL。
mWebview.loadUrl(url);
但这种方法存在一些问题,例如视频往往会自动播放,但最初会卡顿。我需要先按下 暂停,然后再点击 播放 按钮来开始此流。
我无法在我的安卓应用程序中播放Twitch流。
Twitch只提供嵌入式URL来播放流。
我正在使用此URL:https://player.twitch.tv/?channel=CHANNEL_NAME
我正在使用WebView加载此URL。
mWebview.loadUrl(url);
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 );
}