Android-使用服务的浮动窗口上的YouTube Api播放器 [英] Android - YouTube Api player on floating window using service

查看:130
本文介绍了Android-使用服务的浮动窗口上的YouTube Api播放器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆