【问题标题】:How to automatically play Playlist in Spotify Android app如何在 Spotify Android 应用中自动播放播放列表
【发布时间】:2015-05-17 13:01:24
【问题描述】:

我正在尝试在 Spotify 应用中播放一个已知的播放列表。我最好的办法是加载播放列表,但不播放。

我尝试了两件事。首先从搜索中播放:

Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
intent.setComponent(new ComponentName("com.spotify.music",
    "com.spotify.music.MainActivity"));
intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, 
    MediaStore.Audio.Playlists.ENTRY_CONTENT_TYPE);
intent.putExtra(MediaStore.EXTRA_MEDIA_PLAYLIST, <PLAYLIST>);
intent.putExtra(SearchManager.QUERY, <PLAYLIST>);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);

我尝试将 PLAYLIST 替换为已知播放列表的名称。还尝试了“4Rj0zQ0Ux47upeqVSIuBx9”、“spotify:user:11158272501:playlist:4Rj0zQ0Ux47upeqVSIuBx9”等。所有这些都是对这些字符串的搜索失败。

第二次尝试是查看意图:

String uri = "https://play.spotify.com/user/11158272501/playlist/4Rj0zQ0Ux47upeqVSIuBx9";
Intent intent= new Intent( Intent.ACTION_VIEW, Uri.parse(uri) );
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);

这会加载播放列表,但不会播放。如果我随后使用多种方法之一发送 KEYCODE_MEDIA_PLAY 键,它只会恢复当前播放列表,而不是这个新加载的列表。

任何人(包括 Spotify 开发人员)的帮助?

顺便说一句,我不想​​使用 Spotify SDK 来实现我自己的 Spotify 播放器 - 当用户的设备上已经安装了一个非常好的播放器时,不得不这样做似乎很可惜。

【问题讨论】:

  • 来自 Spotify 的任何评论? Nik Reiman,你知道怎么做吗?

标签: android spotify


【解决方案1】:

我从this blog 找到了答案。我缺少的是播放列表 URI 作为意图中的数据 Uri。所以不要使用正确的 Android 搜索方式播放。

因此,使用问题中的第一种方法,您最终会得到:

Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
intent.setData(Uri.parse(
    "spotify:user:11158272501:playlist:4Rj0zQ0Ux47upeqVSIuBx9"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);

需要注意的三件事:

  • Uri 不能是 https://play.spotify...,但必须是冒号分隔的类型。
  • Spotify 帐户必须是高级帐户,否则播放列表会打开但无法播放。
  • 如果屏幕关闭或显示锁定屏幕,此功能将不起作用。 Spotify Activity 需要在加载和播放之前显示在屏幕上!

最后一点意味着它实际上对我不可用...所以还不接受答案。

【讨论】:

  • 这真的有效吗?当我按照这些步骤打开播放列表时,但没有开始播放?
  • 链接失效
【解决方案2】:

只需将:play 添加到Spotify Intent URI

spotify:album:3avifwTCXoRzRxxGM1O0eN:play

【讨论】:

  • 是的,它自 2020 年 8 月 28 日起停止工作,因为 Spotify 政策发生了变化
猜你喜欢
  • 2019-12-25
  • 1970-01-01
  • 2012-05-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-18
  • 1970-01-01
相关资源
最近更新 更多