How do I add an alarm sound(Audio)?
Unsolved
QML and Qt Quick
-
I am writing an alarm clock in QML, I need to add an alarm sound when the alarm date and time reaches the system (in general, the alarm sound is triggered during normal operation of the alarm). How do I do this?
-
Hello @LeoWillian,
You ca create a 1 second timer object to get system current time and play a sound when current times equal to your alarm time:
property var hms: {'hours': 0, 'minutes': 0, 'seconds': 0 } // (object containing integer numbers representing hours, minutes, seconds) Timer { interval: 1000; running: true; repeat: true onTriggered: { var dt = new Date() currentTime = dt.toLocaleTimeString(Qt.locale('EN'), "hh:mm:ss") hms = {'hours': dt.getHours(), 'minutes': dt.getMinutes(), 'seconds': dt.getSeconds()} if (hms.hours === alarmTime.hours && hms.minutes === alarmTime.minutes && hms.seconds === 0) { console.info("ALARM!!!") alarmSound.play() } } } MediaPlayer { id: alarmSound source: "./sounds/pager-beeps.wav" loops: SoundEffect.Infinite audioOutput: AudioOutput {} }
To stop alarm sound you can use:
alarmSound.stop()
Best regards