如何自动播放播放列表在Spotify的Andr​​oid应用 [英] How to automatically play Playlist in Spotify Android app

查看:268
本文介绍了如何自动播放播放列表在Spotify的Andr​​oid应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Spotify的应用程序中播放已知的播放列表。我已经得到了最好是加载播放列表,但不张扬。

I'm trying to play a known playlist in the Spotify app. The best I've got is to load the playlist, but not play it.

两件事情我已经试过。首先从搜索播放:

Two things I've tried. Firstly to play from search:

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);

我试图用已知的播放列表的名称替换播放列表。还试图像4Rj0zQ0Ux47upeqVSIuBx9,Spotify的:用户:11158272501:播放列表:4Rj0zQ0Ux47upeqVSIuBx9等等。所有这些要做的就是一个失败的寻找这些字符串

I've tried replacing PLAYLIST with the name of a known playlist. Also tried things like "4Rj0zQ0Ux47upeqVSIuBx9", "spotify:user:11158272501:playlist:4Rj0zQ0Ux47upeqVSIuBx9" etc. All these do is a failed search for these strings.

第二次尝试查看意图:

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);

这加载播放列表,但不玩了。如果我再使用的许多方法来发送关键code_MEDIA_PLAY关键之一,它只是恢复当前播放列表,而不是这个新加载的列表。

This loads the playlist, but does not play. If I then use one of the many ways to send a KEYCODE_MEDIA_PLAY key, it just resumes the currently playing list, not this newly loaded list.

这是任何人任何帮助(包括Spotify的开发者)?

Any help from anyone (including Spotify devs)?

顺便说一句,我不希望使用Spotify的SDK来实现自己的Spotify的播放器 - 它似乎是一个耻辱,要做到这一点,当一个非常优秀的球员已经在用户的设备上安装

BTW I don't want to use the Spotify SDK to implement my own Spotify Player - it seems a shame to have to do this when a perfectly good player is already installed on a user's device.

推荐答案

我发现从的这个博客。我缺少的是播放列表的URI的意图数据URI。因此,不使用从搜索播放的适当Android的方式。

I found the answer from this blog. What I was missing was the playlist URI as a data Uri in the intent. So not using the proper Android way of Play from search.

因此​​,使用第一种方法的问题,你结束了这一点:

So, using the first method from the question, you end up with this:

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);

3件事情需要注意:

3 things to note:

  • 的URI不能是的https://play.spotify ......但必须是冒号分隔类型。
  • Spotify的帐户必须是premium,否则播放列表打开,但不播放。
  • 这不工作,如果屏幕关闭,或锁屏显示。 Spotify的活动需要在屏幕上显示之前加载和播放!
  • the Uri can't be the https://play.spotify... but has to be the colon seperated type.
  • the Spotify account must be premium, otherwise the playlist opens but does not play.
  • this does not work if the screen is off, or lock screen is showing. The spotify activity needs to display on the screen before it loads and plays!

这最后一点意味着它不适合我实际可用...所以不接受答案了。

This final point means it isn't actually usable for me... so not accepting answer yet.

这篇关于如何自动播放播放列表在Spotify的Andr​​oid应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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