How to play Youtube videos in Android Video View?

后端 未结 8 1430
[愿得一人]
[愿得一人] 2020-12-02 14:24

I am developing an android application which requires a youtube video player embedded within it. I successfully got the RTSP video URL from the API, but while trying to load

8条回答
  •  旧巷少年郎
    2020-12-02 15:10

    After a long search, I found this way of implementation.

     public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.about_fragment, container, false);
    
        String frameVideo = "
    "; WebView displayYoutubeVideo = (WebView) rootView.findViewById(R.id.videoView); displayYoutubeVideo.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { return false; } }); WebSettings webSettings = displayYoutubeVideo.getSettings(); webSettings.setJavaScriptEnabled(true); displayYoutubeVideo.loadData(frameVideo, "text/html", "utf-8"); return rootView; }

    inside the layout.xml:

     
    

    This will work well.

提交回复
热议问题