0

它总是以不同的值触发两次......

这是我的代码:

window.onload = function init() {
  console.log('subscribing')
  player.observe(models.EVENT.CHANGE, function (e) {
    console.log('e.data.curtrack %d', e.data.curtrack)
    console.log('e.data.playstate %d', e.data.playstate)
    console.log('---')
    console.log(player.playing)
  })
}
4

1 回答 1

0

刚刚从 irc 的开发团队直接确认它是一个Spotify 客户端错误。这是一个修复+其他糖果之类的通用事件界面

https://gist.github.com/bc1a7e1c06c1077f238d发射器来自组件仓库https://github.com/component/emitter

使用我的补丁,我们可以做这样的事情:

var sp = getSpotifyApi(1)
var models = sp.require('sp://import/scripts/api/models')
var player = sp.require('player-fix').player

window.onload = function init() {
  console.log('subscribing')

  player.on('play', function () {
    console.log('play')
  }).on('pause', function () {
    console.log('pause')
  }).on('trackChange', function (track) {
    console.log('trackChange', track.data.name)
  }).on('shuffleChange', function (shuffle) {
    console.log('shuffleChange', shuffle)
  }).on('repeatChange', function (repeat) {
    console.log('repeatChange', repeat)
  }).on('volumeChange', function (volume) {
    console.log('volumeChange', volume)
  }).on('contextChange', function () {
    console.log('contextChange')
  })
}
于 2012-11-01T15:42:14.290 回答