May 2019
Intermediate to advanced
542 pages
13h 37m
English
Just as a hardware media player requires a CD, a DVD, or a Blu-ray disc loaded into it to actually play anything back, our QMediaPlayer also needs some kind of content loaded before it can play any audio. Let's explore how to load a sound from a file.
Start by adding a button to the SoundWidget layout, as follows:
self.file_button = qtw.QPushButton( 'Load File', clicked=self.get_file) self.layout().addWidget(self.file_button, 4, 0)
This button calls to the get_file() method, which looks like this:
def get_file(self): fn, _ = qtw.QFileDialog.getOpenFileUrl( self, "Select File", qtc.QDir.homePath(), "Audio files (*.wav *.flac *.mp3 *.ogg *.aiff);; All files (*)" ) if fn: self.set_file(fn)
This method simply calls QFileDialog ...
Read now
Unlock full access