def play_sound_helper(self, sound_file, sound_loop, sound_loop_times): self.media = Phonon.createPlayer(Phonon.MusicCategory, Phonon.MediaSource(sound_file)) if sound_loop_times > 0 and sound_loop: for i in range(sound_loop_times): self.media.enqueue(Phonon.MediaSource(sound_file)) self.media.play()
def __init__(self, parent, mediaFiles): """ @type parent: QtGui.QWidget @type mediaFiles: gui.media.MediaFiles """ self.mediaObject = Phonon.MediaObject(parent) self.audioOutput = Phonon.AudioOutput(Phonon.NotificationCategory, parent) Phonon.createPath(self.mediaObject, self.audioOutput) self._sounds = { JobStatus.FAILING: Phonon.MediaSource(mediaFiles.failing_sound_path()), JobStatus.OK: Phonon.MediaSource(mediaFiles.ok_sound_path()), }
def set_source(self, file_path): """ Creates a media source object from the filepath provided. Args: file_path (str): The file path of the media object. """ self.media_source_obj = Phonon.MediaSource(file_path)
def __init__(self, url=None, parent=None): QWidget.__init__(self) self.setWindowTitle('Audio Player') # 再生ファイル self.url = url # Phonon Objects # *************** self.media = Phonon.MediaObject(self) self.audio = Phonon.AudioOutput(Phonon.VideoCategory, self) Phonon.createPath(self.media, self.audio) # Set SOURCE source = Phonon.MediaSource(self.url) self.media.setCurrentSource(source) # Timer # ***** self.media.setTickInterval(1 / 30 * 1000) # [ms] self.media.tick.connect(self.tock) self.time = 0 # UI 生成 # *************** self.setupUI()
def set_url(self, url): """外部から再生ファイルをセット. ファイルがセットされると状態遷移しStateChangedがコールされる""" self.url = url assert os.path.exists(url) self.media.setCurrentSource(Phonon.MediaSource(url))
class Snorter(): transform = lambda aList: list(map(lambda x: Phonon.MediaSource(x), aList)) MEDIA_FILES = transform( ['./pig1.mp3', './pig2.mp3', './pig3.mp3', './pig4.mp3']) PANIC_MEDIA_FILES = transform([ './pig1_panic.mp3', './pig2_panic.mp3', './pig3_panic.mp3', './pig4_panic.mp3', './pig5_panic.mp3' ]) def __init__(self, pig): audioOutput = Phonon.AudioOutput(Phonon.MusicCategory, pig) self.mediaObject = Phonon.MediaObject(pig) Phonon.createPath(self.mediaObject, audioOutput) self.calmDown() def snort(self): if self.mediaObject.state() == Phonon.StoppedState: random.shuffle(self.mediaFiles) self.mediaObject.enqueue(self.mediaFiles[0]) self.mediaObject.play() def panic(self): self.mediaFiles = self.PANIC_MEDIA_FILES def calmDown(self): self.mediaFiles = self.MEDIA_FILES
def play(file_name): audio.setCurrentSource(Phonon.MediaSource(file_name)) audio.play() loop = QEventLoop() audio.finished.connect(loop.quit) loop.exec_()
def initializeAudioPhonon(self): if self.DEBUG: print "INFO: [Plugin:Orbit] Using Phonon Audio Framework" self.initializeAudioFilePath() self.media = Phonon.MediaObject() #print dir(self.media) audio = Phonon.AudioOutput(Phonon.MusicCategory) Phonon.createPath(self.media, audio) f = QtCore.QFile(self.audio_file) if f.exists(): source = Phonon.MediaSource(self.audio_file) if source.type() != -1: # -1 stands for invalid file self.media.setCurrentSource(source) self.media.play() else: if self.DEBUG: print "ERROR: [Plugin:Orbit] Audio control file invalid:", print self.audio_file else: if self.DEBUG: print "ERROR: [Plugin:Orbit] Audio control file does not exist:," print self.audio_file
def loadFile(self, path): """ Prepares and sets MediaPlayer source. :param path: path to source :type path: str """ if path is None: logger.error("Video source is 'None'") self.errorOccurred.emit() QMessageBox(QMessageBox.Critical, self.error_title, self.loading_error).exec_() return self.source = path mediaSource = Phonon.MediaSource(self.source) if mediaSource.type() != Phonon.MediaSource.LocalFile: logger.error("Video source '%s' could not be loaded" % path) self.errorOccurred.emit() QMessageBox(QMessageBox.Critical, self.error_title, self.source_error).exec_() return self.setCurrentSource(mediaSource) # create the media self.validMedia = True logger.debug("Video source was loaded")
def _ask_open_filename(self): # ask the user for a filename filename, _ = QFileDialog.getOpenFileName( self, 'Open audio file ...', '', 'Audio Files (*.mp3 *.ogg *.wav);;All files (*)') if filename: # load (but don't play!) the file self.media.setCurrentSource(Phonon.MediaSource(filename))
def openFile(self): fileName = QtGui.QFileDialog.getOpenFileName( self, u"Abrir Archivo", u"/", u"Archivos de Audio (*.mp3 *.wav *.ogg)") if fileName[1]: self.path = fileName[0] self.mediaObject.setCurrentSource(Phonon.MediaSource(self.path)) self.ui.btnPlay.setText(">") self.ui.lblNombre.setText("...") self.ui.lcdAvance.display("00:00")
def get_widget_player(file_path, audio): media_src = Phonon.MediaSource(file_path) media_obj = Phonon.MediaObject() media_obj.setCurrentSource(media_src) video_widget = Phonon.VideoWidget() Phonon.createPath(media_obj, video_widget) if audio: audio_out = Phonon.AudioOutput(Phonon.VideoCategory) Phonon.createPath(media_obj, audio_out) return media_obj, video_widget
def schedule_next(self): """ Take the next song from the playlist, send it to the media object, emit the next signal. """ if self.playlist: next_source = self.playlist[self.song_index][0] self.media_object.enqueue(Phonon.MediaSource(next_source)) next_title = self.playlist[self.song_index][1] self.next.emit(next_title)
def play(): url = line_edit_url.text() # Выдираем из url имя файла file_name = os.path.split(urlparse(url).path)[-1] if not os.path.exists(file_name): urlretrieve(url, file_name) audio.setCurrentSource(Phonon.MediaSource(file_name)) audio.play()
def play(self): """ from http://techbase.kde.org/Development/Tutorials/Phonon/Introduction/Python """ self.delayedInit() #self.m_media.setCurrentSource(self.m_model.filePath(index)) self.m_media.setCurrentSource( Phonon.MediaSource( self.separateInstance.files['inputAudioFilename'])) self.m_media.play()
def play(self, filepath): global video_widget media_source = Phonon.MediaSource(filepath) media_obj = Phonon.MediaObject() media_obj.setCurrentSource(media_source) video_widget = Phonon.VideoWidget() Phonon.createPath(media_obj, video_widget) audio_out = Phonon.AudioOutput(Phonon.VideoCategory) Phonon.createPath(media_obj, audio_out) video_widget.show() media_obj.play()
def init_video(main_window): file_path = Utilities.OUTPUT_FOLDER + Utilities.CAMERA_FILE media_src = Phonon.MediaSource(file_path) main_window.media_obj = Phonon.MediaObject(main_window.wdgVideo) main_window.media_obj.setCurrentSource(media_src) main_window.video_widget = Phonon.VideoWidget(main_window.wdgVideo) Phonon.createPath(main_window.media_obj, main_window.video_widget) main_window.video_widget.setGeometry(main_window.wdgVideo.geometry()) main_window.video_widget.show() main_window.media_obj.play() main_window.media_obj.pause()
def handleButtonChoose(self): if self.media.state() == Phonon.PlayingState: self.media.stop() else: dialog = QtGui.QFileDialog(self) dialog.setFileMode(QtGui.QFileDialog.ExistingFile) if dialog.exec_() == QtGui.QDialog.Accepted: path = dialog.selectedFiles()[0] self.media.setCurrentSource(Phonon.MediaSource(path)) self.media.play() dialog.deleteLater()
def delayedInit(self): """ from http://techbase.kde.org/Development/Tutorials/Phonon/Introduction/Python """ if not self.m_media: self.m_media = Phonon.MediaObject(self) audioOutput = Phonon.AudioOutput(Phonon.MusicCategory, self) Phonon.createPath(self.m_media, audioOutput) self.m_media.setCurrentSource( Phonon.MediaSource(\ self.separateInstance.files['inputAudioFilename'])) self.m_media.prefinishMarkReached.connect(self.playStop)
def updateAndPlayNext(self): try: path, n = self.ctrl.next_sample() self.media.setCurrentSource(Phonon.MediaSource(path)) self.setWindowTitle('Sample %s' % n) if not self.ctrl.is_training_sample(): self.slider.setEnabled(False) self.media.play() except IndexError: self.entry.setText("This was the last sample.") self.entry.setEnabled(False) self.buttonStart.setEnabled(False)
def open(self): dialog = QFileDialog() dialog.setViewMode(QFileDialog.Detail) filename = dialog.getOpenFileName(self, 'Open audio file', '/home', "Audio Files (*.mp3 *.wav *.ogg)")[0] self.audio_output = Phonon.AudioOutput(Phonon.MusicCategory, self) Phonon.createPath(self.media_obj, self.audio_output) self.media_obj.setCurrentSource(Phonon.MediaSource(filename)) self.media_obj.tick.connect(self.time_change) self.media_obj.totalTimeChanged.connect(self.total_time_change) self.media_obj.play() self.button.setEnabled(True) self.button.setText("Pause") self.horizontalSlider.setEnabled(True)
def setUp(self): super(TestSimplePlaying, self).setUp() self.app.setApplicationName('Dummy') self.source = Phonon.MediaSource(sample_file) self.media = Phonon.MediaObject() self.media.setCurrentSource(self.source) self.media.finished.connect(self.app.quit) self.called = False # prevent locking with: # request to play a stream, but no valid audio ... self.output = Phonon.AudioOutput() self.path = Phonon.createPath(self.media, self.output)
def addFiles(self): files,_ = QFileDialog.getOpenFileNames(self, self.tr("Select Music Files"), QDesktopServices.storageLocation(QDesktopServices.MusicLocation)) if files=="": return index = len(self.sources) for string in files: self.sources.append(Phonon.MediaSource(string)) if self.sources: self.metaInformationResolver.setCurrentSource(self.sources[index])
def _load_buffer(self): if not self.data_loaded: raise UnboundLocalError("Data not initialized.") stream = cStringIO.StringIO() start = int(self._start * self._real_freq / self.sample_freq) end = min( len(self.data) - 1, int(self._end * self._real_freq / self.sample_freq)) wavfile.write(stream, self._real_freq, self.data[start:end + 1]) if self._buffer.isOpen(): self._buffer.close() self._buffer.setData(stream.read()) self._buffer.open(QtCore.QBuffer.ReadOnly) self._mediaObject.clear() self._mediaObject.setCurrentSource(Phonon.MediaSource(self._buffer)) self.buffer_loaded = True
def agregaCustomVideo(self): largo = 1904 if self.settingsPantallas[self.pantalla][2] == None: self.settingsPantallas[self.pantalla][2] = 1 multiplicador = self.settingsPantallas[self.pantalla][2] if multiplicador == 2: largo = 3820 if multiplicador == 3: largo = 5740 if multiplicador == 4: largo = 7660 customVideo, _ = QFileDialog.getOpenFileName(self, 'Cargar video') self.pantallaActiva.frame.setGeometry(0, 0, largo, 1050) self.pantallaActiva.titleFrame.setVisible(False) self.pantallaActiva.graphFrame.setVisible(False) self.pantallaActiva.fotosFrame.setVisible(False) #self.pantallaActiva.mapFrame.setGeometry(0,0,1900,1050) self.controlesVideo.setVisible(True) #self.pantallaActiva.mapFrame.setGeometry(0,0,1900,1050) media_src = Phonon.MediaSource(customVideo) self.pantallaActiva.media_obj = Phonon.MediaObject( self.pantallaActiva.frame) self.pantallaActiva.media_obj.setCurrentSource(media_src) self.pantallaActiva.video_widget = Phonon.VideoWidget( self.pantallaActiva.frame) self.pantallaActiva.video_widget.setGeometry(0, 0, largo, 1050) Phonon.createPath(self.pantallaActiva.media_obj, self.pantallaActiva.video_widget) audio_out = Phonon.AudioOutput(Phonon.VideoCategory) Phonon.createPath(self.pantallaActiva.media_obj, audio_out) self.pantallaActiva.video_widget.show() self.pantallaActiva.media_obj.play() self.settingsPantallas[self.pantalla][0] = "customVideo" self.settingsPantallas[self.pantalla][1] = customVideo self.settingsPantallas[self.pantalla][2] = multiplicador
def agregaCustomVideo(self): self.guion = False if self.settingsPantallas[ self.pantallaActivaIndex]['multiplicador'] == None: self.settingsPantallas[ self.pantallaActivaIndex]['multiplicador'] = 1 multiplicador = self.settingsPantallas[ self.pantallaActivaIndex]['multiplicador'] self.extiendePantalla(multiplicador) largo = 1920 * multiplicador customVideo, _ = QFileDialog.getOpenFileName(self, 'Cargar video') #self.pantallaActiva.mapFrame.setGeometry(0,0,1900,1050) self.controlesVideo.setVisible(True) #self.pantallaActiva.mapFrame.setGeometry(0,0,1900,1050) media_src = Phonon.MediaSource(customVideo) self.pantallaActiva.media_obj = Phonon.MediaObject( self.pantallaActiva.frame) self.pantallaActiva.media_obj.setCurrentSource(media_src) self.pantallaActiva.video_widget = Phonon.VideoWidget( self.pantallaActiva.frame) self.pantallaActiva.video_widget.setGeometry(0, 0, largo, 1080) Phonon.createPath(self.pantallaActiva.media_obj, self.pantallaActiva.video_widget) audio_out = Phonon.AudioOutput(Phonon.VideoCategory) Phonon.createPath(self.pantallaActiva.media_obj, audio_out) self.pantallaActiva.video_widget.show() self.pantallaActiva.media_obj.play() self.settingsPantallas[ self.pantallaActivaIndex]['type'] = "customVideo" self.settingsPantallas[self.pantallaActivaIndex]['path'] = customVideo self.settingsPantallas[ self.pantallaActivaIndex]['multiplicador'] = multiplicador
def set_source(self, source): self.loop_none() if isinstance(source, basestring): source = [source] source = [i.replace("\\", "/") for i in source] self.__source_files = source self.queue = list() for i in source: source_object = Phonon.MediaSource(i) source_object.Type = 0 self.queue.append(source_object) self.player.clear() self.player.enqueue(self.queue) self.on_play() # if delete current, stop current and restart current_source = self.player.currentSource() if not current_source: return if current_source.fileName() not in self.__source_files: self.player.stop()
def prepare_voice(self, sentence_list, dir_counter): """ Creates the temp folder and puts themin the playlist :param dir_counter: Is used to determine which new temp order should be generated after restarting the application :param sentence_list: List of all sentences/parts of the story/tale """ try: os.mkdir( os.path.join(os.path.dirname(__file__), '..', 'temp_' + str(dir_counter) + '/')) except OSError: pass for idx, sentence in enumerate(sentence_list): time.sleep(0.01) name = query_tts([idx, sentence], dir_counter) self.media_object.enqueue(Phonon.MediaSource(name))
def playSound(self,soundfile): self.mediaObject.clear() self.mediaObject.setCurrentSource(Phonon.MediaSource(soundfile)) self.mediaObject.play()
def _ask_open_filename(self): filename, _ = QFileDialog.getOpenFileName( self, 'Open video ...', '', 'AVI Files (*.avi);;All files (*)') if filename: # load (but don't play!) the given filename self.player.load(Phonon.MediaSource(filename))