How to play background music in KaboomJS - kaboom

I am making a game with the kaboom library and would like to add background music, i read the docs and found const music = play("music"); music.loop() but this seems to only play it once, the file is an MP3 file and i dont get any errors

Related

WAV file with QML SoundEffect audio playback is distorted

My first go at using SoundEffect with QML, and I'm getting mixed results with no clear understanding of why. I can successfully use QML SoundEffect in user interface within an embedded C++ device. The thing I cannot solve is why some WAV files will play perfectly clear, and some will not.
I'm certain my code is correct...its something about how the audio is interpreted. I cannot share the WAV files I'm using...but here's what's happening:
I have two WAV files:
wav_file1_that_works.wav (which is 83kb)
and
wav_file2_that_does_not work.wav (which is 110kb)
Both of these files play just fine in VLC or Media Player or whatever. But when ran through the QML function to play as a feedback for touch on the device, the first WAV file plays just fine, while the second one does not. It does not appear to be a hardware issue as this same issue comes up exactly the same when working on virtual environment. I'm suspecting there is some limitation to using WAV audio within the QT/QML environment? But I cannot find any limits in the documentation. My only suspicion is the file size, or some other specific sound file requirement.
First I declare the sound link to the file:
SoundEffect {
id: playSound
source: "qrc:/wav_file2_that_does_not work.wav"
}
Then on the UI event it's played (not the exact code, but the event certainly works like this:
MyUiItem {
onMyUiTouched: {
playSound.play();
}
}
and file 1 plays perfectly, and file 2 plays, but with a very distorted scratchy sounds.
I probably don't know enough about how WAV file encoding works, but on the surface both files seems to be encoded correctly.
I solved this by refactoring how the app compiles as my WAV file was getting compressed. So unfortunately this was something I discovered that if I let my enterprise deployment system do its thing it compresses everything including all multi-media unless I apply certain parameters to not compress. And so now this works. Thanks for the help.

I want to play only one mp3 file in loop Qt

I have only one mp3 file paying in background. I want that mp3 file to played till I close the application.
What I am facing is that the mp3 file is played for only once and then stops. I want it to be played again.
Find sample code below
Code:
QMediaPlayer *music = new QMediaPlayer();
music->setMedia(QUrl("qrc:/sounds/bgsound.mp3"));
music->setVolume(20);
music->play();
Thanks in advance!!
Simply do it by connecting signals and slots as follows:
connect(music,&QMediaPlayer::mediaStatusChanged,music,&QMediaPlayer::play);

QMediaPlayer can't play MP3's

I need to build a simple mediaplayer for university using QT and I hit a wall.
Everytime I try to play a file (mp3, wav, doensn't matter) I'll just get
DirectShowPlayerService::doSetUrlSource: Unresolved error code 80070020
with every file. The files are not broken, every other player can play them.
It used to work (reading the tags, displaying them and actually playing the file) up until I would go ahead and add a album-artwork to display. The standard QMediaPlayer is used in this project.
I don't quite know where it might have gone wrong, it just stopped working all of a sudden...
I'm on QT 5.2.3 if that's of any help.
Thanks!

Playing audio with directshow from resource file

i am currently writing a script mod for Grand Theft Auto IV using Scripthook C++.
I have been playing audio files by using this template: Simple C++ MP3 Player Class
My problem starts by attempting to use files from resource.
I have no idea how to load them.
Every time i tried to load sound from resource using my code, game crashed.
Already spend hours browsing google about how to play DirectShow audio from resource without any result.
Inside resource files:
(resource.h) #define WAV_Sound 106
(resource.rc) WAV_Sound RCDATA "MySound.wav"
Loading files from HDD is working fine
Load(TEXT("MySound.wav"));
But game crashes when i try one of this:
// Load from resource #1
LPCWSTR file = MAKEINTRESOURCE(WAV_Sound);
Load(file);
// Load from resource #2
Load((LPCWSTR) WAV_Sound);
Hope someone can help me out, thanks !
Microsoft recommended using DirectX Audio to provides multilayer interfaces for developing game, namely XAudio2, X3DAudio, XACT, ... etc, they are very powerful to process sound effect in 2d/3d game environment. Here is the link http://msdn.microsoft.com/en-us/library/ee415737%28v=vs.85%29
Please download and install the DirectX software development kit, and find the 'XAudio2BasicSound' example to open wave file from file or in resource or in dll and playback with IXAudio2 interface, it was very simple example but next step you can add sound effect to your game.

Detect if video has no audio in C++, preferable using Qt Phonon

I am creating a video player if Phonon and Qt. everything is working fine, but when I have a video in my playlist that does not have audio I wish to play another audio.
how can I do that? I mean, how can I detect that the video has no audio?
EDIT: By no audio I meant "no audio channel"
Qt 5 might help you out. Check out Phonon::Gstreamer::MediaObject. The API is similar to the ordinary MediaObject, but with some additional functions. The one you want is audioAvailable().