I am currently using SharpDX SourceVoice to play wav files in a WP8 app, which works fine for playing individual files.
However, I cannot find a way to play multiple files one after another in a loop without registering for events on the SourceVoice and queueing up the next the file. This seems to introduce a bit of stutter and isn't very seamless so I am hoping there is some way to queue both files up once and just loop over them.
There are a few questions around playing two files simultaneously (like this one: Best way to play two audio files simultaneously in Windows Phone 8), but I want to play them one after another in a loop.
The code I have to play a single file looks like:
xaudio = new XAudio2();
masteringVoice = new MasteringVoice(xaudio);
var nativefilestream = new NativeFileStream(String.Format(@"{0}", soundfile),NativeFileMode.Open,NativeFileAccess.Read,NativeFileShare.Read);
var soundstream = new SoundStream(nativefilestream);
var waveFormat = soundstream.Format;
var buffer = new AudioBuffer
{
Stream = soundstream.ToDataStream(),
AudioBytes = (int)soundstream.Length,
Flags = BufferFlags.EndOfStream
};
sourceVoice = new SourceVoice(xaudio, waveFormat, true);
sourceVoice.SubmitSourceBuffer(buffer, soundstream.DecodedPacketsInfo);
sourceVoice.Start();
If I want to loop a single piece of audio, I set the loop count on the AudioBuffer to infinite, as follows:
LoopCount = AudioBuffer.LoopInfinite,
I did try calling the SubmitSourceBuffer method twice with different AudioBuffers, with both having LoopCount set to LoopInfinite, but only the first one played.