May 2019
Intermediate to advanced
542 pages
13h 37m
English
Playing our samples in one-shots is neat, but we'd also like to loop them. Looping audio in a QMediaPlayer object requires a slightly different approach. Instead of loading a QMediaContent object directly, we need to first add it to a QMediaPlayList object. We can then tell the playlist to loop.
Back in our set_file() method, we need to make the following changes to our code:
def set_file(self, url): self.label.setText(url.fileName()) content = qtmm.QMediaContent(url) #self.player.setMedia(content) self.playlist = qtmm.QMediaPlaylist() self.playlist.addMedia(content) self.playlist.setCurrentIndex(1) self.player.setPlaylist(self.playlist)
A playlist can, of course, have multiple files loaded, but, in this case, we only want ...
Read now
Unlock full access