Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes: #921

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions NAudio.Core/Wave/WaveOutputs/WaveFileWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,14 @@ protected override void Dispose(bool disposing)
}
finally
{
// in a finally block as we don't want the FileStream to run its disposer in
// the GC thread if the code above caused an IOException (e.g. due to disk full)
outStream.Dispose(); // will close the underlying base stream
outStream = null;
Type Mem = typeof(MemoryStream);
if (outStream.GetType().Equals(Mem) == false) // Do not close MemoryStreams. This makes them unavailable to the caller
{ // which defeats the purpose as to why WaveFileWriter was called in the first place.
// in a finally block as we don't want the FileStream to run its disposer in
// the GC thread if the code above caused an IOException (e.g. due to disk full)
outStream.Dispose(); // will close the underlying base stream
outStream = null;
}
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions NAudio.Core/Wave/WaveStreams/Mp3FileReaderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,15 @@ private Mp3Frame ReadNextFrame(bool readData)
Mp3Frame frame = null;
try
{
frame = Mp3Frame.LoadFromStream(mp3Stream, readData);
if (frame != null)
if (mp3Stream != null) // in case we're called after the stream is closed
{
tocIndex++;
frame = Mp3Frame.LoadFromStream(mp3Stream, readData);
if (frame != null)
{
tocIndex++;
}
}

}
catch (EndOfStreamException)
{
Expand Down
11 changes: 7 additions & 4 deletions NAudio.Wasapi/WasapiOut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,14 @@ private void PlayThread()
}
}
Thread.Sleep(latencyMilliseconds / 2);
audioClient.Stop();
if (playbackState == PlaybackState.Stopped)
if (audioClient != null) // avoid null reference (probably due to timing issues)
{
audioClient.Reset();
}
audioClient.Stop();
if (playbackState == PlaybackState.Stopped)
{
audioClient.Reset();
}
}
}
catch (Exception e)
{
Expand Down