Two sounds at once?

Current version of Xojo, Windows 10 latest version.

If I play a piece of music, it seems to stop as soon as I play a sound effect on the same screen. Is there a way to have two sounds going at once? (I want the music to be in the background of the window).

Thanks!

How do you play it? Using two players?

Just using the nameoffile.Play command. Is there another way to do it?

I think that using high-level commands allows you to play only one sound.

If you want to play multiple sounds at once, you would need to use a specific system library

[quote=415528:@StphaneMons]I think that using high-level commands allows you to play only one sound.
If you want to play multiple sounds at once, you would need to use a specific system library[/quote]

What would be a good method of doing this with the least dependencies? (Windows)

This is a bug in Xojo Windows that was reported back in November of 2016. I was creating a Windows Desktop game and background theme music and a sound effect could not be played at the same time.

<https://xojo.com/issue/45781>

It looks like I was supposed to receive an email on this case, and I might have missed it. I created examples in the “I Wish I Knew How To… Implement Declares with Xojo on Windows” and have examples on how to do this with examples in Chapter 16. Maybe Xojo can implement declares to fix this bug?

[quote=415540:@Eugene Dakin]This is a bug in Xojo Windows that was reported back in November of 2016. I was creating a Windows Desktop game and background theme music and a sound effect could not be played at the same time.

<https://xojo.com/issue/45781>
[/quote]

I would like to see this resolved somehow, as I want to play a sound effect for moving over buttons and have background music at the same time. Is there a workaround anyone knows of?

I have an app that plays up to four tones in Windows at the same time. It does so by loading four different “sound” files and playing them. Below is a snippet of the code that plays the tones:

//set volume for files pySoundFile0.Volume = pyToneLevel(0) pySoundFile1.Volume = pyToneLevel(1) pySoundFile2.Volume = pyToneLevel(2) pySoundFile3.Volume = pyToneLevel(3) //play files for timer duration pySoundFile0.PlayLooping pySoundFile1.PlayLooping pySoundFile2.PlayLooping pySoundFile3.PlayLooping
pySoundFile_x is a Sound object (http://documentation.xojo.com/api/os/sound.html)

I last compiled this application for Windows on 2015 so I can’t say if anything broke in Xojo since then. Volume in Windows is not implemented correctly (feedback://showreport/?report_id=39028), but that is another story.

Thanks! I think this won’t help me as they need to be played on demand, and not all at the exact same time.

I did create a Feedback case for it, #54252. Hopefully, it can be addressed soon.

I once wrote an independent WindowsPlayerMBS class (in MBS Xojo Audio Plugin) to work with playing MP3 in memory, which could help you here.
Several instances can play at the same time.

The following example was based on what I showed before but using the mediaplayer object. It plays either two WAV files or MP3 files, you control when.

https://www.dropbox.com/s/7r3lqxzvh4vuit0/dual%20audio%20player%20with%20mediaplayer.zip?dl=1

Sample program using SoundPlayer:
https://www.dropbox.com/s/v257yl1l4a3z1in/dual%20audio%20player%20with%20soundplayer.zip?dl=1

Hmm, this project made me discover something: it works fine if I use an .mp3 for the music and .wav format for the sound effect, even stock Xojo without this project. Then the music doesn’t stop when the sound starts. Does Xojo have a channel for each format? Is this by design?

@Derek DiBenedetto ; did you try using the MoviePlayer? I tried 2017r2.1 with the Sound object and it certainly looks like Xojo had a regression in Windows as it worked in 2014 and 2015 (as Eugene mentioned). This is not surprising and I wouldn’t hold my breath on a fix. But using the MoviePlayer worked fine in 2017r2.1

Looks like (based on my Feedback case) that its a limitation of Windows ‘DirectSound’ implementation; two .mp3s can’t play at once. Two .wavs can play or a .mp3 and a .wav together, but not two .mp3s. Odd, but its fairly simple to work around, I suppose.

I urge you to convert any sound files in your apps to the highest quality WAV format that you can. One, for the reason above, and Two, for the best quality playback.