Reputation: 1736
I am unable to play Twitch Streams in my Android application. Twitch is only providing their embed url for playing Streams.
I am using this url: https://player.twitch.tv/?channel=CHANNEL_NAME
I am using a WebView to load this url by
mWebview.loadUrl(url);
But this method has several issues, like the video tends to autoplay but gets stuck initially. I need to press Pause first and then the Play button to start this stream.
Upvotes: 4
Views: 1168
Reputation: 907
Try using this code.
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 );
}
Upvotes: 1