1

私はサウンドボードプログラムに取り組んでいます。ウィンドウには、以下の SoundPlayer クラスの複数のインスタンスが表示されます。私のプログラムを実行すると、音量スライダーは自分のプレーヤーには影響しません。最後に開始されたプレーヤーの音量スライダーは、プログラム全体の音量を制御します。audioObjects、volumeSliders などのすべてのインスタンスを出力しましたが、それらのいずれもプレイヤー間で共有されていません。各プレーヤーに音量を出力させました。正しい音量スライダーを使用すると音量が変わります (audioOutput.volume()) が、可聴効果はありません。最後に開始されたボリューム スライダーを使用すると、他のプレーヤーの audioOutput ボリュームはボリューム値を変更しませんが、可聴効果があります。これは複数のWindowsマシンでは完全に正常に機能しますが、ubuntu 12.04では機能しないため、途方に暮れています。

編集: 問題は audioOutput にもっとあるようです。いくつかのボタンを .setVolume() に接続し、音量を手動で調整したところ、以前と同じようにバグが発生しました。最後に開始されたプレーヤーの音量のみが実際に可聴音に影響を与えます。これはすべてのプレーヤーに対して行われます。

SoundPlayer クラス: (UI 設定の一部は簡潔にするために削除されています。重要な部分には、audioOutputs と MediaObjects が作成される createAttr()/loadAttr() と、ボリューム スライダーが作成される setupUi() が含まれます。)

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))
4

1 に答える 1