问题
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