1
import xbmc
2
from threading import Timer
3
4
class PandaPlayer( xbmc.Player ):
5
6
	def __init__( self, core=None, panda=None ):
7
		xbmc.Player.__init__( self, xbmc.PLAYER_CORE_MPLAYER )
8
		self.panda = panda
9
		self.timer = None
10
11
	def playSong( self, item ):
12
		self.play( item[0], item[1] )
13
14
	def play( self, url, item ):
15
		xbmc.Player(xbmc.PLAYER_CORE_MPLAYER).play( url, item )
16
17
	def onPlayBackStarted( self ):
18
		print "PANDORA: onPlayBackStarted: %s" %self.getPlayingFile()
19
		if self.panda.playing:
20
			if not "pandora.com" in self.getPlayingFile():
21
				self.panda.playing = False
22
				self.panda.quit()
23
			else:
24
				#Show Visualization (disappears after each song...)
25
				xbmc.executebuiltin( "ActivateWindow( 12006 )" )
26
27
	def onPlayBackEnded( self ):
28
		print "PANDORA: onPlayBackEnded"
29
		self.stop()
30
		print "PANDORA: playing = %s" %self.panda.playing
31
		if self.timer and self.timer.isAlive():
32
			self.timer.cancel()
33
		if self.panda.skip:
34
			self.panda.skip = False
35
		if self.panda.playing:
36
			self.timer = Timer( 0.5, self.panda.playNextSong )
37
			self.timer.start()
38
39
	def onPlayBackStopped( self ):
40
		print "PANDORA: onPlayBackStopped"
41
		self.stop()
42
		print "PANDORA: playing = %s" %self.panda.playing
43
		if self.timer and self.timer.isAlive():
44
			self.timer.cancel()
45
		if self.panda.playing:
46
			if self.panda.skip:
47
				self.panda.skip = False
48
			self.timer = Timer( 0.5, self.panda.playNextSong )
49
			self.timer.start()