Using NAudio 1.6.0.0
When the code below is running in a console application under Windows Embedded Standard 8, it doesn't raise the "PlaybackStopped" event.
The exact same application works fine under Windows 7 (haven't tested it under "normal" Windows 8).
I also tried to change the wavePlayer to the following (with the given result):
- DirectSoundOut: Plays the sound, doesn't raise the event
- WaveOut: Doesn't play the sound at all
- WaveOutEvent: Plays the sound, doesn't raise the event
- AsioOut: Plays the sound, doesn't raise the event
I also tried (after reading some postings on StackOverflow) to use the WaveChannel32 (with padding disabled) in many of the above situations (including DirectSoundOut) and none resulted in the event being fired.
```
internal class FileItem : ItemBase
{
private readonly IWavePlayer wavePlayer;
private readonly WaveStream reader;
private bool disposed;
public FileItem(string fileName)
{
this.fileName = fileName;
this.wavePlayer = new new DirectSoundOut();
this.reader = new AudioFileReader(fileName);
this.wavePlayer.Init(this.reader);
this.wavePlayer.PlaybackStopped += this.WavePlayerOnPlaybackStopped;
}
public override void Start()
{
this.wavePlayer.Play();
}
public override void Stop()
{
this.wavePlayer.Stop();
}
public override void Dispose()
{
if (this.disposed)
{
return;
}
this.disposed = true;
ThreadPool.QueueUserWorkItem(
s =>
{
this.wavePlayer.PlaybackStopped -= this.WavePlayerOnPlaybackStopped;
this.wavePlayer.Stop();
this.reader.Dispose();
this.wavePlayer.Dispose();
});
}
private void WavePlayerOnPlaybackStopped(object sender, StoppedEventArgs e)
{
this.RaiseCompleted(EventArgs.Empty);
}
}
```
(Code simplified to focus on real issue; might not compile "as is")
Comments: I'm surprised NAudio works at all on Windows Embedded Standard. Your result for WaveOut not playing is expected - the default callback model uses windows messages, and there is no message loop in a console app. I can't quite understand why there is no event raised. Maybe something funny is going on with the SynchronizationContext, which I use to try to raise the PlaybackStopped on the GUI thread if there is one (obviously there isn't in your case, so it should just raise it from the background thread of the output device).
When the code below is running in a console application under Windows Embedded Standard 8, it doesn't raise the "PlaybackStopped" event.
The exact same application works fine under Windows 7 (haven't tested it under "normal" Windows 8).
I also tried to change the wavePlayer to the following (with the given result):
- DirectSoundOut: Plays the sound, doesn't raise the event
- WaveOut: Doesn't play the sound at all
- WaveOutEvent: Plays the sound, doesn't raise the event
- AsioOut: Plays the sound, doesn't raise the event
I also tried (after reading some postings on StackOverflow) to use the WaveChannel32 (with padding disabled) in many of the above situations (including DirectSoundOut) and none resulted in the event being fired.
```
internal class FileItem : ItemBase
{
private readonly IWavePlayer wavePlayer;
private readonly WaveStream reader;
private bool disposed;
public FileItem(string fileName)
{
this.fileName = fileName;
this.wavePlayer = new new DirectSoundOut();
this.reader = new AudioFileReader(fileName);
this.wavePlayer.Init(this.reader);
this.wavePlayer.PlaybackStopped += this.WavePlayerOnPlaybackStopped;
}
public override void Start()
{
this.wavePlayer.Play();
}
public override void Stop()
{
this.wavePlayer.Stop();
}
public override void Dispose()
{
if (this.disposed)
{
return;
}
this.disposed = true;
ThreadPool.QueueUserWorkItem(
s =>
{
this.wavePlayer.PlaybackStopped -= this.WavePlayerOnPlaybackStopped;
this.wavePlayer.Stop();
this.reader.Dispose();
this.wavePlayer.Dispose();
});
}
private void WavePlayerOnPlaybackStopped(object sender, StoppedEventArgs e)
{
this.RaiseCompleted(EventArgs.Empty);
}
}
```
(Code simplified to focus on real issue; might not compile "as is")
Comments: I'm surprised NAudio works at all on Windows Embedded Standard. Your result for WaveOut not playing is expected - the default callback model uses windows messages, and there is no message loop in a console app. I can't quite understand why there is no event raised. Maybe something funny is going on with the SynchronizationContext, which I use to try to raise the PlaybackStopped on the GUI thread if there is one (obviously there isn't in your case, so it should just raise it from the background thread of the output device).