Python PyQt5.QtMultimedia.QMediaContent() Examples
The following are 17
code examples of PyQt5.QtMultimedia.QMediaContent().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
PyQt5.QtMultimedia
, or try the search function
.
Example #1
Source File: audio.py From imperialism-remake with GNU General Public License v3.0 | 7 votes |
def load_soundtrack_playlist(): """ Loads the play list of the soundtracks and replaces the file name with the full path. A playlist is a list where each entry is a list of two strings: file path, title """ global soundtrack_playlist # create playlist soundtrack_playlist = QtMultimedia.QMediaPlaylist() soundtrack_playlist.setPlaybackMode(QtMultimedia.QMediaPlaylist.Loop) # read information file data = utils.read_as_yaml(constants.SOUNDTRACK_INFO_FILE) # add the soundtrack folder to each file name for entry in data: file = constants.extend(constants.SOUNDTRACK_FOLDER, entry[0]) url = qt.local_url(file) media = QtMultimedia.QMediaContent(url) soundtrack_playlist.addMedia(media)
Example #2
Source File: music_player.py From code-jam-5 with MIT License | 6 votes |
def play_song(self, song: str): """Play a song given its file url in the local filesystem.""" self.player.playlist().clear() self.controls.duration_label.setText('Loading...') url = QtCore.QUrl.fromLocalFile(song) if self.check_advert_intermission(): self.player.playlist().addMedia(QtMultimedia.QMediaContent(url)) else: self.player.playlist().insertMedia( self.player.playlist().nextIndex(), QtMultimedia.QMediaContent(url) ) if self.player.playlist().mediaCount() == 1: self.controls.toggle_play() else: self.controls._next_song() self.controls.duration_label.setText('0') self.controls.play_pause_button.setIcon(QtGui.QIcon(imgButtons.Pause.str))
Example #3
Source File: player.py From MusicBox with MIT License | 6 votes |
def play(self): try: media = self.musics[self.currentIndex] except: logger.error("unknow error. musics info: {0}".format(self.musics)) return if type(media) == str: if 'http' in media or 'file' in media: content = QMediaContent(QUrl(media)) else: content = QMediaContent(QUrl.fromLocalFile(media)) self.musics = self.musics[:self.currentIndex] + [content] + self.musics[self.currentIndex+1:] media = content self.parent.setMedia(media) self.parent.playMusic() self.tabMusicEvent()
Example #4
Source File: player.py From MusicBox with MIT License | 6 votes |
def setCurrentIndex(self, index): try: media = self.musics[index] except: logger.error("unknow error. musics info: {0}".format(self.musics)) return if type(media) == str: if 'http' in media or 'file' in media: content = QMediaContent(QUrl(media)) else: content = QMediaContent(QUrl.fromLocalFile(media)) self.musics = self.musics[:index] + [content] + self.musics[index+1:] self.parent.setMedia(content) else: self.parent.setMedia(media) self.parent.playMusic() self.tabMusicEvent() self.currentIndex = index
Example #5
Source File: controls.py From code-jam-5 with MIT License | 5 votes |
def _open_file(self): """Opens an audio file and adds it to the playlist.""" song = QtWidgets.QFileDialog.getOpenFileName(self, "Open Song", "", "Sound Files (*.mp3)") if song[0]: url = QtCore.QUrl.fromLocalFile(song[0]) if not self.player.playlist().mediaCount(): self.player.playlist().addMedia(QtMultimedia.QMediaContent(url)) self.toggle_play() else: self.player.playlist().addMedia(QtMultimedia.QMediaContent(url))
Example #6
Source File: definitionsdialog.py From Lector with GNU General Public License v3.0 | 5 votes |
def play_pronunciation(self): if not self.pronunciation_mp3 or not multimedia_available: return media_content = QtMultimedia.QMediaContent( QtCore.QUrl(self.pronunciation_mp3)) player = QtMultimedia.QMediaPlayer(self) player.setMedia(media_content) player.play()
Example #7
Source File: music_player.py From code-jam-5 with MIT License | 5 votes |
def disable_advert_controls(self, media: QtMultimedia.QMediaContent): """Disable player controls while an ad is playing.""" if self.advert_in_progress: self.now_playing_widget.audio_visualiser.green_flames() self.controls.setEnabled(False) self.advert_in_progress = False else: self.now_playing_widget.audio_visualiser.red_flames() self.controls.setEnabled(True)
Example #8
Source File: now_playing.py From code-jam-5 with MIT License | 5 votes |
def _media_changed(self, media: QtMultimedia.QMediaContent): """Update 'Now playing' label when a new song is selected.""" filename = media.canonicalUrl().fileName() song_name = '.'.join(filename.split('.')[:-1]) self.now_playing_label.setText(song_name)
Example #9
Source File: captains_log.py From Mastering-GUI-Programming-with-Python with MIT License | 5 votes |
def on_file_selected(self, item): fn = item.text() url = qtc.QUrl.fromLocalFile(self.video_dir.filePath(fn)) content = qtmm.QMediaContent(url) self.player.setMedia(content) self.player.play() ####################### # Recording callbacks # #######################
Example #10
Source File: soundboard.py From Mastering-GUI-Programming-with-Python with MIT License | 5 votes |
def set_file(self, url): self.label.setText(url.fileName()) if url.scheme() == '': url.setScheme('file') content = qtmm.QMediaContent(url) #self.player.setMedia(content) # Looping # must retain a reference to the playlist # hence self.playlist self.playlist = qtmm.QMediaPlaylist() self.playlist.addMedia(content) self.playlist.setCurrentIndex(1) self.player.setPlaylist(self.playlist) self.loop_cb.setChecked(False)
Example #11
Source File: media_player.py From PyIntroduction with MIT License | 5 votes |
def addMedia(self, media_file): media_content = QMediaContent(QUrl.fromLocalFile(media_file)) self._playlist.addMedia(media_content) # クリックでポーズ・再生の切り替え
Example #12
Source File: mediaplayer.py From QMusic with GNU Lesser General Public License v2.1 | 5 votes |
def setMediaUrl(self, url): if url.startswith('http'): _url = QUrl(url) else: _url = QUrl.fromLocalFile(url) gPlayer.setMedia(QMediaContent(_url)) self.playToggle(self._isPlaying)
Example #13
Source File: player.py From MusicBox with MIT License | 5 votes |
def saveCookies(self): with open(self.musicsCookiesFolder, 'wb') as f: for row, data in enumerate(self.musics): if type(data) == QMediaContent: url = data.canonicalUrl().toString() self.musics[row] = url pickle.dump(self.musics, f) with open(self.mediaListCookiesFolder, 'wb') as f: pickle.dump(self.mediaList, f)
Example #14
Source File: player.py From MusicBox with MIT License | 5 votes |
def addMedias(self, url, data): # url为QMediaContent, data包含这个歌曲的信息。{name, author, url, music_id} self.parent.setMedia(url) self.musics.append(url) self.currentIndex = len(self.musics) - 1 self.mediaList[url.canonicalUrl().toString()] = data self.parent.playMusic() # window self.playWidgets.parent.systemTray.setToolTip('{0}-{1}'.format(data['name'], data['author']))
Example #15
Source File: player.py From MusicBox with MIT License | 5 votes |
def setMusic(self, url, data): """设置当前的音乐,可以直接用网络链接。""" if url: if 'http' in url or 'file' in url: self.playList.addMedias(QMediaContent(QUrl(url)), data) else: self.playList.addMedias(QMediaContent(QUrl.fromLocalFile(url)), data) return True return False
Example #16
Source File: playback.py From dunya-desktop with GNU General Public License v3.0 | 5 votes |
def set_source(self, audio_path): url = QUrl.fromLocalFile(audio_path) media = QMediaContent(url) self.setNotifyInterval(35) self.setMedia(media)
Example #17
Source File: QgsFmvPlayer.py From QGISFMV with GNU General Public License v3.0 | 4 votes |
def playFile(self, videoPath, islocal=False, klv_folder=None): ''' Play file from path @param videoPath: Video file path @param islocal: Check if video is local,created using multiplexor or is MISB @param klv_folder: klv folder if video is created using multiplexor ''' self.islocal = islocal self.klv_folder = klv_folder try: # Remove All Data self.RemoveAllData() self.clearMetadata() QApplication.processEvents() # Create Group root = QgsProject.instance().layerTreeRoot() node_group = QgsLayerTreeGroup(videoPath) #If you have a loaded project, insert the group #on top of it. root.insertChildNode(0, node_group) self.fileName = videoPath self.playlist = QMediaPlaylist() self.isStreaming = False if "://" in self.fileName: self.isStreaming = True if self.isStreaming: # show video from splitter (port +1) oldPort = videoPath.split(":")[2] newPort = str(int(oldPort) + 10) proto = videoPath.split(":")[0] url = QUrl(proto + "://127.0.0.1:" + newPort) else: url = QUrl.fromLocalFile(videoPath) qgsu.showUserAndLogMessage("", "Added: " + str(url), onlyLog=True) self.playlist.addMedia(QMediaContent(url)) self.player.setPlaylist(self.playlist) self.setWindowTitle(QCoreApplication.translate( "QgsFmvPlayer", 'Playing : ') + os.path.basename(videoPath)) CreateVideoLayers(hasElevationModel(), videoPath) self.HasFileAudio = True if not self.HasAudio(videoPath): self.actionAudio.setEnabled(False) self.actionSave_Audio.setEnabled(False) self.HasFileAudio = False self.playClicked(True) except Exception as e: qgsu.showUserAndLogMessage(QCoreApplication.translate( "QgsFmvPlayer", 'Open Video File : '), str(e), level=QGis.Warning)