def play(self, report=False):
if self.is_pause:
self.is_pause = False
if self.idx < len(self.playlist):
if self.idx == -1:
self.idx = 0
if not self.random:
song = self.playlist[self.idx]
else:
song = random.choice(self.playlist)
self.song = song
subprocess.Popen("pkill play", shell=True)
if report:
song['mp3_url'] = self.netease.songs_detail_new_api(
[song['song_id']])[0]['url']
mp3_url = song['mp3_url']
if mp3_url is None:
self.next()
self.cond.wait()
try:
if report:
self.mic.say(u"即将播放:%s,%s" % (
song['artist'], song['song_name']))
time.sleep(.1)
subprocess.Popen("play -v %f %s" % (
self.volume, mp3_url), shell=True, stdout=subprocess.PIPE)
self.cond.notify()
self.cond.wait(int(song.get('playTime')) / 1000)
except:
pass
else:
try:
subprocess.Popen("pkill play", shell=True)
self.cond.notify()
self.cond.wait()
except:
pass