Simple audio playback
Quite often, applications need to playback sounds in response to GUI events, as you might do in a game or just to provide audio feedback for user actions. For this application, QtMultimedia offers the QSoundEffect class. QSoundEffect is limited to playing back uncompressed audio, so it works with Pulse Code Modulation (PCM), Waveform data (WAV) files but not MP3 or OGG files. The trade-off is that it is low-latency and very efficient with resources, so while it's not useful as a general-purpose audio player, it is perfect for fast playback of sound effects.
To demonstrate QSoundEffect, let's build a phone dialer. Copy the application template from Chapter 4, Building Applications with QMainWindow, into a new file called ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access