Android-使用服务的浮动窗口上的YouTube Api播放器 [英] Android - YouTube Api player on floating window using service
问题描述
我想将YouTube播放器实现为Android上的浮动窗口(在所有应用程序之上).
I like to implement YouTube Player as a floating window (on top all apps) on Android.
I saw many apps that do the same like this one
我试图了解如何实现它.
And I try to Understand how to implement it.
我尝试过这个:
wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
LayoutInflater li = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
View vi = li.inflate(R.layout.youtube_view,null);
YouTubePlayerView youTubeView = vi.findViewById(R.id.youtube_view);
youTubeView.initialize(DeveloperKey.DEVELOPER_KEY, this);
但是出现此错误:
Caused by: java.lang.IllegalStateException: A YouTubePlayerView can only be created with an Activity which extends YouTubeBaseActivity as its context
这很明显-随着我扩展Service而不是YouTubeBaseActivity
And it is obvious - as I extends Service and not YouTubeBaseActivity
所有那些浮动的YouTube应用程序都使用webview作为播放器容器吗?还是我错过了使用官方 Youtube Player API
Did all those floating YouTube apps use webview as the player container ? or did i miss better solution using the official Youtube Player API
推荐答案
他们正在使用基于WebView的播放器.您可以在此处找到一个开源实现: android-youtube-player
They are using a WebView-based player. You can find an opensource implementation here: android-youtube-player
这篇关于Android-使用服务的浮动窗口上的YouTube Api播放器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!