use*_*043 17 android audio-player android-music-player
有没有办法从我的应用程序开始在Google音乐播放器应用程序中播放歌曲?我正在尝试关注代码,但谷歌音乐播放器只打开搜索结果并且实际上不播放该歌曲.
Intent intent = new Intent();
intent.setAction(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
intent.putExtra(SearchManager.QUERY, "It's my life");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setPackage("com.google.android.music");
activity.startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH的文档说明如下:意图执行搜索音乐媒体并尽可能自动播放结果中的内容.
所以,根据文档,它应该能够播放这首歌.但是,它只会打开搜索结果而不会播放.我在这里缺少什么想法?
谢谢你尽你所能的帮助.
我找到了一种方法来做到这一点。
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(YOUR_SONG_URI);
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
796 次 |
| 最近记录: |