如何在python、Windows中下载和使用QtMultimedia?

问题描述

如何在 pyqt5 中使用 QtMultimedia。 我使用的是 Windows 操作系统。

我研究了 QtMultimedia 但我仍然不知道如何下载它,你能帮我吗?

解决方法

如果您已经安装了 PyQt,那么您只需要将其添加到您的代码中:

import PyQt5.QtMultimedia

如果没有,则可以使用 pip 命令 PyQt 安装 pip install PyQt5

要使用它,请查看 the PyQt source code where they include examples of QtMultimedia

仅此而已。以下是您可以使用的一个简单示例:

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)