Pyspotify - 周期性"轨道无法播放错误"

时间:2015-04-12 20:06:40

标签: python

我有pyspotify的问题。我正在尝试搜索艺术家名称,获取他们的顶级曲目列表,然后播放其中一个。这是我的代码段:

    search_string = "artist:"+artist_to_find
    result = session.search(search_string)
            result.load()
    print result.track_total
    browser = result.artists[0].browse()
    browser.load()
    print browser.tophit_tracks
    for track in browser.tophit_tracks:
    print track.name, track
            toptracks = browser.tophit_tracks
    print "error check"
    if toptracks!=-1:
        print "------------------"
        tracktoplay=choice(toptracks)
        rand = randint(0,10)
        print "random track number = %s" %rand
        tracktoplay = browser.tophit_tracks[rand]
        print tracktoplay.link
        print tracktoplay.name
        print "------------------"
        session.player.load(tracktoplay)
        session.player.play()

我经常在没有先前曲目完成的情况下调用此代码。 Perodically(每隔几个轨道)我收到以下错误:

random track number = 7
spotify:track:6vQN2a9QSgWcm74KEZYfDL
Take A Chance On Me
------------------
Traceback (most recent call last):
  File "../jj.py", line 146, in <module>
    app.run()
  File "../jj.py", line 116, in run
    conversation.handleForever()
  File "/home/mh/Projects/jjo/client/conversation.py", line 44, in handleForever
    listen(self)
  File "/home/mh/Projects/jjo/client/new_play.py", line 110, in listen
    play(self,response)
  File "/home/mh/Projects/jjo/client/new_play.py", line 194, in play
    session.player.load(tracktoplay)
  File "/usr/local/lib/python2.7/dist-packages/spotify/player.py", line 45, in load
    self._session._sp_session, track._sp_track))
  File "/usr/local/lib/python2.7/dist-packages/spotify/error.py", line 30, in maybe_raise
    raise LibError(error_type)
spotify.error.LibError: The track cannot be played

任何人都可以建议我做错了吗?

由于

1 个答案:

答案 0 :(得分:0)

我没有spotify的经验,但我出于好奇而看着它。

如果我是你,我会在调用play之前检查PlayerState是否已加载()

希望它有所帮助。