How to play HLS video in Android?

我们两清 提交于 2019-12-05 19:53:33

This code works for me: (Android 5.1 Nexus 4)

public class TwitchFragment extends Fragment implements View.OnClickListener {

@Nullable
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
                         final Bundle savedInstanceState) {
    final View root = inflater.inflate(R.layout.fragment_twitch, null, false);

    Button buttonTwitch = (Button) root.findViewById(R.id.buttonTwitch);
    buttonTwitch.setOnClickListener(this);

    return root;
}

@Override
public void onClick(final View v) {
    FrameLayout layout = (FrameLayout) getView();
    assert layout != null;
    layout.removeView(v);

    WebView webView = new WebView(ESportLiveScoreApplication.getInstance());

    layout.addView(webView);

    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setUseWideViewPort(false);
    webSettings.setDomStorageEnabled(true);
    webSettings.setSaveFormData(true);
    webSettings.setLoadWithOverviewMode(true);

    final WebChromeClient webChromeClient = new WebChromeClient();

    webView.setWebChromeClient(webChromeClient);
    webView.loadUrl("http://www.twitch.tv/h2p_gucio/hls");
}
}

I don't know why but it work only when i put WebView into FrameLayout :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!