AudioManager.qml Example File

demos/ChickenOutbreak2/qml/AudioManager.qml
 import Felgo 3.0
 import QtQuick 2.0
 import QtMultimedia 5.0

 Item {
   id: audioManager

   // Use Sound IDs to play Sounds e.g. audioManager.play(audioManager.idBADCORN)
   property int idBADCORN: 11
   property int idCORN: 22
   property int idGAMEOVER: 33
   property int idMENUCLICK: 44
   property int idPARACHUTE: 55
   property int idPLING: 66
   property int idPOWERUP: 77
   property int idSLOWMO: 88
   property int idSLOWMOOFF: 99
   property int idTELEPORT: 111
   property int idTICK: 222

   property bool toggleCORN

   // Use Music IDs to play Music. e.g. audioManager.playMusic(audioManager.idMusicBG)
   property int idMusicBG: 111

   function play(clipID) {
     // if settings disable do not play sounds
     if(!settings.soundEnabled)
       return

     switch(clipID) {
     case idBADCORN:
       clipBADCORN.play()
       break
     case idCORN:
       if(toggleCORN) clipCORN_1.play()
       else clipCORN_2.play()
       toggleCORN = !toggleCORN
       break
     case idGAMEOVER:
       clipGAMEOVER.play()
       break
     case idMENUCLICK:
       clipMENUCLICK.play()
       break
     case idPARACHUTE:
       clipPARACHUTE.play()
       break
     case idPLING:
       clipPLING.play()
       break
     case idPOWERUP:
       clipPOWERUP.play()
       break
     case idSLOWMO:
       clipSLOWMO.play()
       break
     case idSLOWMOOFF:
       clipSLOWMOOFF.play()
       break
     case idTELEPORT:
       clipTELEPORT.play()
       break
     case idTICK:
       clipTICK.play()
       break
     }
   }

   function playMusic(trackID) {
     // if settings disable do not play sounds
     if(!settings.musicEnabled)
       return

     switch(trackID) {
     case idMusicBG:
       music.source = "../assets/snd/bg-new.wav"
       break
     }

     music.play()
   }

   function stopMusic() {
     music.stop()
   }

   BackgroundMusic {
     id: music
   }

   Audio {
     id: clipBADCORN
     source: "../assets/snd/badCoin.wav"
     volume: 1
   }
   Audio {
     id: clipCORN_1
     source: "../assets/snd/corn.wav"
     volume: 1
   }
   Audio {
     id: clipCORN_2
     source: "../assets/snd/corn.wav"
     volume: 1
   }
   Audio {
     id: clipGAMEOVER
     source: "../assets/snd/gameOver.wav"
     volume: 1
   }
   Audio {
     id: clipMENUCLICK
     source: "../assets/snd/menuclick.wav"
     volume: 1
   }
   Audio {
     id: clipPARACHUTE
     source: "../assets/snd/parachute.wav"
     volume: 1
   }
   Audio {
     id: clipPLING
     source: "../assets/snd/pling.wav"
     volume: 1
   }
   Audio {
     id: clipPOWERUP
     source: "../assets/snd/powerup.wav"
     volume: 1
   }
   Audio {
     id: clipSLOWMO
     source: "../assets/snd/SlowMo.wav"
     volume: 1
   }
   Audio {
     id: clipSLOWMOOFF
     source: "../assets/snd/SlowMoOut.wav"
     volume: 1
   }
   Audio {
     id: clipTELEPORT
     source: "../assets/snd/teleport.wav"
     volume: 1
   }
   Audio {
     id: clipTICK
     source: "../assets/snd/tick.wav"
     volume: 1
   }

   Component.onCompleted: {
     playMusic(idMusicBG)
   }
 }

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support