我希望能够禁用 Spotify 中的“下一个”和“上一个”按钮。我知道这是可能的,因为 soundrop 应用程序已经做到了。
我已经搜索了一下,据我了解,我应该播放上下文为空的曲目或仅包含 1 首曲目的上下文。我一直在测试我能想到的所有可能的解决方案,但它们似乎都不起作用。它们中的大多数实际上会导致在上下文为 null 的情况下播放曲目,但始终启用 Next/Previous 按钮。
如果我按下下一个按钮,播放器最终不会播放任何曲目,并且两个按钮都被禁用......
下面是我的测试应用程序的代码。
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 转换为链接”
提前致谢