可以从 Android 应用程序跳过曲目吗?
我正计划为 Android 2.1 开发一个应用程序,该应用程序每分钟都会更改歌曲(通过我希望 Android 中存在的“下一个”),以便使用音频设备 atm 的应用程序。
因此,如果我已经在后台运行 Spotify 播放音乐,我可以通过我的程序切换到下一首曲目吗?
如果我有任何不清楚的地方请告诉我。 提前致谢!
I'm planning on doing a application for Android 2.1 that changes song every minute (through what I hope exists in Android, "next") for the application using the audio device atm.
So if I have Spotify running in background already, playing music, can I through my program change to the next track?
Let me know if I was unclear about anything.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我知道这是一个有点老的问题,但我花了一些时间搜索除此处提到的内容之外的其他内容。
有一个解决方法 - 广播媒体按钮操作。有一个问题 - 接收者可以识别广播是来自系统还是来自另一个应用程序,因此他们可以忽略非系统广播。
I know this is a bit old question, but it took me some time searching something other then what is mentioned here.
There is a workaround - broadcasting media button action. There is one catch - receiver can recognize if the broadcast was from system or from another app, so they can ignore the non-system broadcasts.
音乐应用程序没有通用的音频传输 API,因此您需要查看您所定位的音乐应用程序是否公开公开服务绑定或意图。如果没有,您将无法执行此操作。
There's no universal audio transport API for music applications, so you'd need to see if the music applications you're targeting publicly expose service bindings or intents. If not, you won't be able to do this.
刚刚发布了相关答案此处
使用AudioManager的dispatchMediaKeyEvent()方法和定义的KeyEvent对我有用最新的SDK。
Just posted a relevant answer here
Using the AudioManager's dispatchMediaKeyEvent() method with a defined KeyEvent worked for me using the latest SDK.
系统音乐主屏幕小部件为内置音乐播放器发送此意图:
但看起来这可能需要一些黑客才能在音乐应用程序本身中实现外部包,因为 MediaPlaybackService 只接受显式意图并且无法从外部访问。 此帖子似乎表明有可能不过,黑客行为。
但即便如此,正如罗曼所说,并不是每个音乐播放器都会尊重这个意图。您必须与 Spotify/Pandora/Last.fm 本身核实,看看他们是否有任何可用的意图来进行这样的绑定。
The system music homescreen widget sends this intent for the built-in music player:
But it looks like this might take some hackery to implement outside packages in the music app itself because the MediaPlaybackService only accepts explicit Intents and isn't accessible from the outside. This thread seems to indicate it's possible with a bit of hackery, though.
But even then, as Roman said, not every music player will respect that Intent. You'll have to check with Spotify/Pandora/Last.fm themselves and see if they have any available intents to bind like that.
看起来可以使用 AudioManager 来注入媒体密钥。
这是 另一个问题
同样的方式你可以注入PlayPause按钮和其他一些按钮。
我已经在控制 Youtube 的后台服务中对其进行了测试,它适用于 Android 6
Looks that it's possible to use AudioManager to inject media keys.
Here is a snippet from another question
The same way you can inject PlayPause button and some others.
I've tested it within a background service controlling Youtube and it worked for Android 6