Reputation: 399
If I create an AsioOut and use the MultiplexingWaveProvider it works fine (plays / disposes etc..) only if I call AsioOut.Stop() before MultiplexingWaveProvider has run out of data.
If I wait until the MultiplexingWaveProvider has run out of data (and AsioOut has triggered a PlaybackStopped event) I can't Dispose of AsioOut it just hangs and never returns (no error). Note: there is no Dispose() on the MultiplexingWaveProvider, but I've tried calling dispose on the all WaveFileReaders that are used for the MultiplexingWaveProvider.
Upvotes: 0
Views: 790
Reputation: 399
This is my implimentaion of Mark's answer. I had to use the IWaveProvidor because the MultiplexingWaveProvider I am using doesn't support the ISampleProvidor. (I could have also implemented a MultiplexingWaveProvider to get the same result I think). Note the task used to not have the stop being called inside the data handler.
public class AsioWavProvidor :IWaveProvider
{
private bool EndSignaled = false;
public Action EndofAudioData;
public Mp3FileReader Mp3Reader;
public AsioWavProvidor(string mp3File)
{
Mp3Reader = new Mp3FileReader(mp3File);
}
public TimeSpan CurrentTime { get { return Mp3Reader.CurrentTime; } }
public int Read(byte[] buffer, int offset, int count)
{
var retCount = Mp3Reader.Read(buffer, offset, count);
if (retCount == 0)
{
if (EndofAudioData != null && !EndSignaled)
{
EndSignaled = true;
System.Threading.Tasks.Task.Run(() =>
{
try
{
EndofAudioData();
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
});
}
return count;
}
return retCount;
}
Upvotes: 0
Reputation: 49522
I've had a couple of people report issues with ASIO drivers when trying to automatically stop. Probably some drivers don't like it if stop is called within the buffer swap callback.
Ideally AsioOut
should be updated to offer an option to disable auto stopping. You could simulate this by creating a never-ending ISampleProvider
whose Read
method returns silence after the end of the source has been reached. Then you could poll to see when the end of your input had been reached, and then Stop
and Dispose
when its done
Upvotes: 2