Spotify API - 播放器EVENT.CHANGE触发两次

时间:2012-11-01 11:11:39

标签: spotify

它使用不同的值始终触发两次......

这是我的代码:

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

1 个答案:

答案 0 :(得分:0)

直接从irc的开发团队确认它是 Spotify客户端错误。 这是修复 +其他糖果,例如常见事件界面

https://gist.github.com/bc1a7e1c06c1077f238d Emitter来自组件仓库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')
  })
}