本文整理汇总了Python中PyQt5.QtMultimedia.QMediaContent方法的典型用法代码示例。如果您正苦于以下问题:Python QtMultimedia.QMediaContent方法的具体用法?Python QtMultimedia.QMediaContent怎么用?Python QtMultimedia.QMediaContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtMultimedia
的用法示例。
在下文中一共展示了QtMultimedia.QMediaContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: play
# 需要导入模块: from PyQt5 import QtMultimedia [as 别名]
# 或者: from PyQt5.QtMultimedia import QMediaContent [as 别名]
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()
示例2: setCurrentIndex
# 需要导入模块: from PyQt5 import QtMultimedia [as 别名]
# 或者: from PyQt5.QtMultimedia import QMediaContent [as 别名]
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
示例3: load_soundtrack_playlist
# 需要导入模块: from PyQt5 import QtMultimedia [as 别名]
# 或者: from PyQt5.QtMultimedia import QMediaContent [as 别名]
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)
示例4: play_song
# 需要导入模块: from PyQt5 import QtMultimedia [as 别名]
# 或者: from PyQt5.QtMultimedia import QMediaContent [as 别名]
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))
示例5: play_pronunciation
# 需要导入模块: from PyQt5 import QtMultimedia [as 别名]
# 或者: from PyQt5.QtMultimedia import QMediaContent [as 别名]
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()
示例6: set_source
# 需要导入模块: from PyQt5 import QtMultimedia [as 别名]
# 或者: from PyQt5.QtMultimedia import QMediaContent [as 别名]
def set_source(self, audio_path):
url = QUrl.fromLocalFile(audio_path)
media = QMediaContent(url)
self.setNotifyInterval(35)
self.setMedia(media)
示例7: setMusic
# 需要导入模块: from PyQt5 import QtMultimedia [as 别名]
# 或者: from PyQt5.QtMultimedia import QMediaContent [as 别名]
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
示例8: addMedias
# 需要导入模块: from PyQt5 import QtMultimedia [as 别名]
# 或者: from PyQt5.QtMultimedia import QMediaContent [as 别名]
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']))
示例9: saveCookies
# 需要导入模块: from PyQt5 import QtMultimedia [as 别名]
# 或者: from PyQt5.QtMultimedia import QMediaContent [as 别名]
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)
示例10: setMediaUrl
# 需要导入模块: from PyQt5 import QtMultimedia [as 别名]
# 或者: from PyQt5.QtMultimedia import QMediaContent [as 别名]
def setMediaUrl(self, url):
if url.startswith('http'):
_url = QUrl(url)
else:
_url = QUrl.fromLocalFile(url)
gPlayer.setMedia(QMediaContent(_url))
self.playToggle(self._isPlaying)
示例11: addMedia
# 需要导入模块: from PyQt5 import QtMultimedia [as 别名]
# 或者: from PyQt5.QtMultimedia import QMediaContent [as 别名]
def addMedia(self, media_file):
media_content = QMediaContent(QUrl.fromLocalFile(media_file))
self._playlist.addMedia(media_content)
# クリックでポーズ・再生の切り替え
示例12: set_file
# 需要导入模块: from PyQt5 import QtMultimedia [as 别名]
# 或者: from PyQt5.QtMultimedia import QMediaContent [as 别名]
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)
示例13: on_file_selected
# 需要导入模块: from PyQt5 import QtMultimedia [as 别名]
# 或者: from PyQt5.QtMultimedia import QMediaContent [as 别名]
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 #
#######################
示例14: _media_changed
# 需要导入模块: from PyQt5 import QtMultimedia [as 别名]
# 或者: from PyQt5.QtMultimedia import QMediaContent [as 别名]
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)
示例15: disable_advert_controls
# 需要导入模块: from PyQt5 import QtMultimedia [as 别名]
# 或者: from PyQt5.QtMultimedia import QMediaContent [as 别名]
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)