Fixed Mp3Loader and OggLoader not resetting stream position

This commit is contained in:
penev92
2022-01-04 23:58:55 +02:00
committed by Matthias Mailänder
parent 87b92b53a4
commit 6fb228ddd1
2 changed files with 30 additions and 14 deletions

View File

@@ -48,6 +48,9 @@ namespace OpenRA.Mods.Common.AudioLoaders
readonly Stream stream;
public Mp3Format(Stream stream)
{
var startPosition = stream.Position;
try
{
mp3 = new MP3Stream(stream);
this.stream = stream;
@@ -63,6 +66,11 @@ namespace OpenRA.Mods.Common.AudioLoaders
}
catch { }
}
finally
{
stream.Position = startPosition;
}
}
Stream Clone(Mp3Format cloneFrom)
{

View File

@@ -48,16 +48,24 @@ namespace OpenRA.Mods.Common.AudioLoaders
readonly Stream stream;
public OggFormat(Stream stream)
{
var startPosition = stream.Position;
try
{
this.stream = stream;
reader = new VorbisReader(stream);
LengthInSeconds = (float) reader.TotalTime.TotalSeconds;
reader = new VorbisReader(stream, false);
LengthInSeconds = (float)reader.TotalTime.TotalSeconds;
}
finally
{
stream.Position = startPosition;
}
}
OggFormat(OggFormat cloneFrom)
{
stream = SegmentStream.CreateWithoutOwningStream(cloneFrom.stream, 0, (int)cloneFrom.stream.Length);
reader = new VorbisReader(stream)
reader = new VorbisReader(stream, false)
{
// Tell NVorbis to clip samples so we don't have to range-check during reading.
ClipSamples = true