Android - YouTube Api player on floating window using service

帅比萌擦擦* 提交于 2020-01-22 02:37:07

问题


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.

I tried this :

 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);

But get This error :

Caused by: java.lang.IllegalStateException: A YouTubePlayerView can only be created with an Activity  which extends YouTubeBaseActivity as its context

And it is obvious - as I extends Service and not YouTubeBaseActivity

Did all those floating YouTube apps use webview as the player container ? or did i miss better solution using the official Youtube Player API


回答1:


They are using a WebView-based player. You can find an opensource implementation here: android-youtube-player



来源:https://stackoverflow.com/questions/51253825/android-youtube-api-player-on-floating-window-using-service

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