我希望能够在spotify中禁用Next和之前的按钮。 我知道这是可能的,因为音色应用已经设法做到了。
我已经搜索了一下,根据我的理解,我应该播放一个上下文为null的轨道或仅包含一个轨道的上下文。我一直在测试我能想到的所有可能的解决方案,但它们似乎都没有用。其中大多数实际上导致轨道被上下文播放为null,但是下一个/上一个按钮总是被启用。
如果我按下一个按钮,播放器最终不播放任何曲目,并且两个按钮都被禁用...
以下是我的测试应用程序的代码。
var sp = getSpotifyApi(1);
var models = sp.require('sp://import/scripts/api/models');
var views = sp.require('sp://import/scripts/api/views');
models.player.observe(models.EVENT.CHANGE, function (o) {
console.log(['Player Change', o, models.player.context]);
})
$('#play1').click(function () {
models.Track.fromURI("spotify:track:5A1fNC7Fdb0yyh3UA6T1ef", function (track) {
console.log(["play1", track.name]);
models.player.play(track, null);
});
});
$('#play2').click(function () {
models.Track.fromURI("spotify:track:5A1fNC7Fdb0yyh3UA6T1ef", function (track) {
console.log(["play2", track.name]);
var p = new views.Player();
p.play(track, null);
});
});
$('#play3').click(function () {
models.Track.fromURI("spotify:track:5A1fNC7Fdb0yyh3UA6T1ef", function (track) {
console.log(["play3", track.name]);
var pl = new models.Playlist();
pl.add(track);
models.player.play(track, pl);
});
});
$('#play4').click(function () {
console.log(["play4"]);
models.player.play("spotify:track:5A1fNC7Fdb0yyh3UA6T1ef", null);
});
$('#play5').click(function () {
models.Track.fromURI("spotify:track:5A1fNC7Fdb0yyh3UA6T1ef", function (track) {
models.player.playTrack(track);
});
});
$('#play6').click(function () {
models.Track.fromURI("spotify:track:5A1fNC7Fdb0yyh3UA6T1ef", function (track) {
console.log(["play6", track.name]);
var pl = new models.Playlist();
pl.add(track);
models.player.playTrackWithContext(track, pl, 0);
});
});
$('#play7').click(function () {
var l = new models.Link("spotify:track:5A1fNC7Fdb0yyh3UA6T1ef");
sp.trackPlayer.setContextCanSkipNext(l, false);
console.log(["play7", models.player, sp.trackPlayer],l);
models.player.play(l, null);
});
来自#play1的结果:
["play1", "Jag är här nu"]
["Player Change", Object, null]
来自#play2的结果:
["play2", "Jag är här nu"]
["Player Change", Object, null]
来自#play3的结果:
["play3", "Jag är här nu"]
["Player Change", Object, "spotify:internal:temp_playlist:spotify:app:myapplication@687556942764"]
来自#play4的结果:
["play4"]
["Player Change", Object, null]
来自#play5的结果:
["play5", "Jag är här nu"]
["Player Change", Object, null]
来自#play6的结果:
["play6", "Jag är här nu"]
["Player Change", Object, "spotify:internal:temp_playlist:spotify:app:myapplication@217702072872"]
来自#play7的结果:
sp.trackPlayer.setContextCanSkipNext(l, false);
以上行生成一个例外消息"无法将参数0转换为链接"
提前致谢
答案 0 :(得分:1)
我现在做了一些工作后,发现了如何做到这一点。
models.Track.fromURI("spotify:track:5A1fNC7Fdb0yyh3UA6T1ef", function (track) {
var pl = new models.Playlist();
sp.trackPlayer.setContextCanSkipPrev(pl.uri, false);
sp.trackPlayer.setContextCanSkipNext(pl.uri, false);
pl.add(track);
models.player.play(track, pl);
});
希望这有助于其他任何人尝试解决此问题并陷入关于播放具有空背景的轨道的讨论......