Advertisement
Guest User

Untitled

a guest
Feb 26th, 2013
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1. class PhononThread(QtCore.QThread):
  2.     # output = QtCore.pyqtSignal(basestring)
  3.    
  4.     def __init__(self, url, volumeChanged_slot, tick_slot, parent=None):
  5.         QtCore.QThread.__init__(self, parent)
  6.         self._terminated = False
  7.        
  8.         self.url = url
  9.         self.volumeChanged_slot = volumeChanged_slot
  10.         self.tick_slot = tick_slot
  11.         self.start()
  12.    
  13.     @utils.decorators.log_exceptions(Exception, log)
  14.     def run(self): # Called by Qt once the thread environment has been set up.
  15.         mediaSource = Phonon.MediaSource(self.url) # creates a media source
  16.         mediaSource.setAutoDelete(True)
  17.         audioOutput = Phonon.AudioOutput(Phonon.MusicCategory) # create an audio output device
  18.         audioOutput.setVolume(config.listen_volumeSlider_volume)
  19.         audioOutput.volumeChanged.connect(self.volumeChanged_slot)
  20.        
  21.         self.player = Phonon.MediaObject() # creates the audio handler
  22.         self.player.setCurrentSource(mediaSource) # loads the media source in the audio handler
  23.        
  24.         Phonon.createPath(self.player, audioOutput) # links the audio handler and the audio output device
  25.        
  26.         self.player.setTickInterval(100)
  27.         self.player.tick.connect(self.tick_slot)
  28.        
  29.         self.player.play()
  30.        
  31.     def play(self):
  32.         self.player.play()
  33.        
  34.     def stop(self):
  35.         self.player.stop()
  36.        
  37.     def pause(self):
  38.         self.player.pause()
  39.    
  40.     def terminate(self):
  41.         "Setting _terminated to True"
  42.         self._terminated = True
  43.         super(PhononThread, self).terminate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement