Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How do I add an alarm sound(Audio)?
Forum Updated to NodeBB v4.3 + New Features

How do I add an alarm sound(Audio)?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 405 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LeoWillian
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • ndiasN Offline
      ndiasN Offline
      ndias
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved