How to play YouTube video in popup popup in android

I can create a popup popup using the standalone library https://github.com/pingpongboss/StandOut . As far as I understand, this library creates a service that creates a popup.

The Youtube API for Android provides YouTubePlayerView, which can only be used with YoutubeBaseActivity and which I can not use, since the floating-point pop-up refers to the service.

The Youtube API also provides YoutubePlayerFragment, which also cannot be used, because services cannot work with fragments.

There is also a WebView that you can use here, which is not as good as the Youtube API for Android, but better than nothing. It almost works for me. The webview is displayed inside the popup popup and the video is playing, but the video is just black.

Here is the webview code

    private static final String FRAME_VIDEO = "<html><body>Video From YouTube<br><iframe width=\"320\" height=\"280\" src=\"https://www.youtube.com/embed/_oEA18Y8gM0\" frameborder=\"0\"></iframe></body></html>";


    WebView webView = (WebView) findViewById(R.id.webView);
    webView.setWebViewClient(new WebViewClient(){
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return false;
        }
    });
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setPluginState(WebSettings.PluginState.ON);
    webView.setWebChromeClient(new WebChromeClient());
    webView.loadData(FRAME_VIDEO, "text/html", "utf-8");

Perhaps one of these options is possible:

  • Somehow use YoutubePlayerView without YouTubeBaseActivity

  • Use fragments without activity

  • Fix WebView Code

  • There may be another way to play youtube videos inside a popup popup

+4
source share

Source: https://habr.com/ru/post/1655763/


All Articles