Fixed Mp3Loader and OggLoader not resetting stream position
This commit is contained in:
committed by
Matthias Mailänder
parent
87b92b53a4
commit
6fb228ddd1
@@ -49,19 +49,27 @@ namespace OpenRA.Mods.Common.AudioLoaders
|
||||
|
||||
public Mp3Format(Stream stream)
|
||||
{
|
||||
mp3 = new MP3Stream(stream);
|
||||
this.stream = stream;
|
||||
|
||||
// Make a first guess based on the file size and bitrate
|
||||
// This should be fine for constant bitrate files
|
||||
LengthInSeconds = mp3.Length * 8f / (2f * Channels * SampleRate);
|
||||
|
||||
var startPosition = stream.Position;
|
||||
try
|
||||
{
|
||||
// Attempt to parse a more accurate length from the file metadata;
|
||||
LengthInSeconds = (float)new TagLib.Mpeg.AudioFile(new StreamAbstraction(stream)).Properties.Duration.TotalSeconds;
|
||||
mp3 = new MP3Stream(stream);
|
||||
this.stream = stream;
|
||||
|
||||
// Make a first guess based on the file size and bitrate
|
||||
// This should be fine for constant bitrate files
|
||||
LengthInSeconds = mp3.Length * 8f / (2f * Channels * SampleRate);
|
||||
|
||||
try
|
||||
{
|
||||
// Attempt to parse a more accurate length from the file metadata;
|
||||
LengthInSeconds = (float)new TagLib.Mpeg.AudioFile(new StreamAbstraction(stream)).Properties.Duration.TotalSeconds;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
finally
|
||||
{
|
||||
stream.Position = startPosition;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
Stream Clone(Mp3Format cloneFrom)
|
||||
|
||||
@@ -49,15 +49,23 @@ namespace OpenRA.Mods.Common.AudioLoaders
|
||||
|
||||
public OggFormat(Stream stream)
|
||||
{
|
||||
this.stream = stream;
|
||||
reader = new VorbisReader(stream);
|
||||
LengthInSeconds = (float) reader.TotalTime.TotalSeconds;
|
||||
var startPosition = stream.Position;
|
||||
try
|
||||
{
|
||||
this.stream = stream;
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user