简体   繁体   中英

C# SoundPlayer Question

I'm trying to get one .wav file to play as ambient music though when another sound is played, it halts the ambient music and I've tried doing play-loop and tried the various sync, async , load.

I think I'm missing something here. Thank you in advance.

Check this question on SO and the suggestions made there. The basic problem is that SoundPlayer can only play one sound stream at a time - if you want to play multiple sounds concurrently you need a different solution.

It is possible to use Windows Media Player for the ambient sound, and play another sound with SoundPlayer at the same time:

// example begin
WMPLib.WindowsMediaPlayer mediaPlayer = new WMPLib.WindowsMediaPlayer();
mediaPlayer.URL = "<theAudioFile>";
mediaPlayer.settings.setMode("loop", true);
mediaPlayer.controls.play();
// example end

A reference to Windows Media Player assembly needs to be added to the solution as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM