def _make_output(self, output_info, data, volume): output = QtMultimedia.QAudioOutput(output_info, output_info.preferredFormat()) output.setVolume(volume) output.stateChanged.connect(lambda: self._delete_output(output)) buffer = QtCore.QBuffer() buffer.open(QtCore.QIODevice.ReadWrite) buffer.write(data) buffer.seek(0) output.start(buffer) return output
def run(self, pixmap, graphics_view, loop=False): self.loop = loop self.pixmap = pixmap self.graphics_view = graphics_view self.timer = QtCore.QTimer(self.graphics_view) self.timer.timeout.connect(self.update_frame) self.timer.start(self.period_ms * 1000) self.t = 0 if self.audio_format is not None: self.audio_output = QtMultimedia.QAudioOutput( self.audio_format, self.graphics_view ) self.audio_output.stateChanged.connect(self.audio_state_handler) # start audio streaming self.audio_input.open(QtCore.QIODevice.ReadOnly) self.audio_output.start(self.audio_input) self.display_frame() self.graphics_view.fitInView(self.pixmap, QtCore.Qt.KeepAspectRatio)