-2

How can I use QtMultimedia in pyqt5. I am using Windows operating system.

I researched about QtMultimedia but I still don't know how to download it, can you help me?

The Pilot Dude
  • 2,091
  • 2
  • 6
  • 24
Baris_Ertan
  • 23
  • 1
  • 5

1 Answers1

0

If you have PyQt already installed, then you only need to add this to your code:

import PyQt5.QtMultimedia

If you don't, then you can install PyQt with the pip command pip install PyQt5.

To use it, check out the PyQt source code where they include examples of QtMultimedia

That's all there is to it. Here is one quick example you can use:

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) 
The Pilot Dude
  • 2,091
  • 2
  • 6
  • 24
  • It should be noted that, at least on Linux, "extra" modules like QtMultimedia, QtCharts or QtWebEngine are not always installed by default depending on the distribution, and have to be manually added. While the OP is on Windows (on which I *think* it's installed by default, but I'm not completely sure), it's worth noticing it. And then there's also the issue about plugins, but that's another story. – musicamante Apr 07 '21 at 00:42