Question

I'm working on a soundboard program. The window is populated with multiple instances of the below SoundPlayer class. When running my program the volume sliders don't affect their own player. The last initiated player's volume slider controls the volume for the entire program. I've printed out all the instances of the audioObjects, volumeSliders, etc, and none of them are shared between players. I had each player print out it's volume, and using the correct volume sliders does change the volume (audioOutput.volume()), but with no audible effect. Using the last initated volume slider the audioOutput volume for the other players doesn't change the volume value but yet there is an audible effect. I'm at a loss since this works perfectly fine on multiple Windows machines but not on ubuntu 12.04. After seeking help elsewhere and running this on multiple machines I'm beginning to think it's a PySide/Phonon problem with linux?

EDIT: Seems the problem lies more with audioOutput. I connected some buttons to .setVolume() and manually adjusted the volume and it bugged out the same as before. Only the last initiated player's volume actually affects the audible sound, and do so for every player.

SoundPlayer class: (Some of the ui setting up was trimmed for brevity. Key parts include createAttr()/loadAttr() where the audioOutputs and MediaObjects are created, and setupUi() where the volume sliders are created.)

class SoundPlayer():
  def __init__(self, MainWindow, position, instance, attributes):
    self.instance = instance
    self.mainWindow = MainWindow
    self.pos = position
    self.setupUi(self.pos)
    if attributes == '':
      self.createAttr()
      self.attributes = [self.name, self.filename]
    else:
      self.attributes = attributes
      self.loadAttr()
    self.buttons()
    self.directory = QDesktopServices.storageLocation(QDesktopServices.MusicLocation)

  def updateDevice(self, device):
    self.audio.setOutputDevice(device)
    Phonon.createPath(self.media, self.audio)

  def loadAttr(self):
    self.name = self.attributes[0]
    self.filename = self.attributes[1]
    self.media = Phonon.MediaObject(self.instance)
    self.audio = Phonon.AudioOutput(Phonon.MusicCategory, self.instance)
    self.source = Phonon.MediaSource(self.filename)
    Phonon.createPath(self.media, self.audio)
    self.label.setText(self.name)
    self.updateUi()

  def createAttr(self):
    self.filename = ''
    self.name = 'None'
    self.media = Phonon.MediaObject(self.instance)
    self.audio = Phonon.AudioOutput(Phonon.MusicCategory, self.instance)
    self.source = Phonon.MediaSource(self.filename)
    Phonon.createPath(self.media, self.audio)
    self.media.stateChanged.connect(lambda x,y: self.changed(x,y))
    self.label.setText(self.name)
    self.updateUi()

  def saveAttr(self):
    self.attributes = [self.name, self.filename]

  def buttons(self):
    self.playButton.clicked.connect(self.onplaybutton())
    self.resetButton.clicked.connect(self.onresetbutton())
    self.stopButton.clicked.connect(self.onstopbutton())
    self.optionButton.clicked.connect(self.optionDialog())

  def onplaybutton(self):
    state = self.media.state()
    if state != Phonon.State.PausedState and state != Phonon.State.PlayingState:
      self.playButton.setIcon(QtGui.QIcon(":pause.png"))
      self.media.setCurrentSource(self.source)
      self.media.play()
    elif state == Phonon.State.PlayingState:
      self.playButton.setIcon(QtGui.QIcon(":play.png"))
      self.media.pause()
    elif state == Phonon.State.PausedState:
      self.playButton.setIcon(QtGui.QIcon(":pause.png"))
      time = self.media.currentTime()
      self.media.play()
      self.media.seek(time)

  def onresetbutton(self):
    self.media.setCurrentSource(self.source)
    self.media.play()
    self.playButton.setIcon(QtGui.QIcon(":pause.png"))

  def onstopbutton(self):
    self.media.stop()
    self.playButton.setIcon(QtGui.QIcon(":play.png"))

  def updateUi(self):
    self.seek = Phonon.SeekSlider(self.media, self.widget)
    self.seek.resize(111, 21)
    self.seek.show()
    self.volume = Phonon.VolumeSlider(self.audio, self.volumeWidget)
    self.volume.resize(111, 21)
    self.volume.show()
    self.playButton.setIcon(QtGui.QIcon(":play.png"))
    self.media.stateChanged.connect(lambda x,y: self.changed(x,y))
Was it helpful?

Solution

Most probably not your fault: https://bugs.kde.org/show_bug.cgi?id=321288

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top