The project application ch11-drum-machine displays four SoundEffectWidget widgets: kickWidget, snareWidget, hihatWidget, and crashWidget.
Each SoundEffectWidget widget displays a QLabel and a QPushButton. The label displays the sound name. If the button is clicked, a sound is played.
The Qt Multimedia module provides two main ways to play an audio file:
- QMediaPlayer: This file can play songs, movies, and internet radio with various input formats
- QSoundEffect: This file can play low-latency .wav files
This project example is a virtual drum machine, so we are using a QSoundEffect object. The first step to using a QSoundEffect is to update your .pro file as shown in the following code:
QT += core gui multimedia
Then you can initialize the sound. Here is an example of how to do this:
QUrl urlKick("qrc:/sounds/kick.wav"...