[英]How do I connect widget to my background service which is used to play music?
I'm trying to build a basic music player but right now I'm stuck at making widget for it. 我正在尝试构建一个基本的音乐播放器,但现在我仍然坚持为其制作小部件。 Can someone tell me how do I connect widget to the background service?
有人可以告诉我如何将小部件连接到后台服务吗? I'm using MediaBrowser,MediaController on the client side and MediaBrowserService,MediaSession in the background service.
我在客户端使用MediaBrowser,MediaController,在后台服务中使用MediaBrowserService,MediaSession。 So, to create a instance of MediaController, I require activity which isn't available in widget class if I'm not wrong and if I try to bind widget class to service using bindService and returning an instance of the background service class method I'm getting error (which is resolved once I comment the onBind method in the service)
因此,要创建MediaController的实例,我需要活动,如果我没有记错,并且如果我尝试使用bindService将小部件类绑定到服务并返回背景服务类方法的实例,则该活动在小部件类中不可用m出现错误(一旦我在服务中注释了onBind方法,该错误就会解决)
How do I proceed? 我该如何进行?
AppWidgetProvider is a BroadcastReceiver on steroids. AppWidgetProvider是类固醇上的BroadcastReceiver 。 But you can't bind to service from BroadcastReceivers (That was done because BroadcastReceiver is lightweight component that have shot livetime (10 seconds)).
但是您不能绑定到BroadcastReceivers的服务(之所以这样做,是因为BroadcastReceiver是轻量级的组件,具有实时播放时间(10秒))。 In your case best way to communicate with music service is use broadcasts (pending intents).
在您的情况下,与音乐服务进行通讯的最佳方法是使用广播(有待处理的意图)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.