mirror of
https://github.com/ppy/osu
synced 2024-12-25 08:12:41 +00:00
Use TagLib instead of ManagedBass
This commit is contained in:
parent
f0cd18a721
commit
8f093b9a11
26
osu.Game/IO/FileAbstraction/StreamFileAbstraction.cs
Normal file
26
osu.Game/IO/FileAbstraction/StreamFileAbstraction.cs
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.IO;
|
||||
|
||||
namespace osu.Game.IO.FileAbstraction
|
||||
{
|
||||
public class StreamFileAbstraction : TagLib.File.IFileAbstraction
|
||||
{
|
||||
public StreamFileAbstraction(string filename, Stream fileStream)
|
||||
{
|
||||
ReadStream = fileStream;
|
||||
Name = filename;
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
public Stream ReadStream { get; }
|
||||
public Stream WriteStream => ReadStream;
|
||||
|
||||
public void CloseStream(Stream aStream)
|
||||
{
|
||||
aStream.Position = 0;
|
||||
}
|
||||
}
|
||||
}
|
@ -3,8 +3,7 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using ManagedBass;
|
||||
using osu.Framework.Audio.Callbacks;
|
||||
using osu.Game.IO.FileAbstraction;
|
||||
using osu.Game.Rulesets.Edit.Checks.Components;
|
||||
using osu.Game.Storyboards;
|
||||
|
||||
@ -52,9 +51,27 @@ namespace osu.Game.Rulesets.Edit.Checks
|
||||
}
|
||||
|
||||
Stream data = context.WorkingBeatmap.GetStream(storagePath);
|
||||
var fileCallbacks = new FileCallbacks(new DataStreamFileProcedures(data));
|
||||
int decodeStream = Bass.CreateStream(StreamSystem.NoBuffer, BassFlags.Decode, fileCallbacks.Callbacks, fileCallbacks.Handle);
|
||||
if (decodeStream == 0)
|
||||
StreamFileAbstraction fileAbstraction = new StreamFileAbstraction(filename, data);
|
||||
|
||||
// We use TagLib here for platform invariance; BASS cannot detect audio presence on Linux.
|
||||
TagLib.File tagFile = null;
|
||||
string errorReason = null;
|
||||
|
||||
try
|
||||
{
|
||||
tagFile = TagLib.File.Create(fileAbstraction);
|
||||
}
|
||||
catch (TagLib.CorruptFileException) { errorReason = "Corrupt file"; }
|
||||
catch (TagLib.UnsupportedFormatException) { errorReason = "Unsupported format"; }
|
||||
|
||||
if (errorReason != null)
|
||||
{
|
||||
yield return new IssueTemplateFileError(this).Create(filename, errorReason);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tagFile.Properties.AudioChannels == 0)
|
||||
continue;
|
||||
|
||||
yield return new IssueTemplateHasAudioTrack(this).Create(filename);
|
||||
|
@ -42,5 +42,6 @@
|
||||
<PackageReference Include="SharpCompress" Version="0.28.3" />
|
||||
<PackageReference Include="NUnit" Version="3.13.2" />
|
||||
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
|
||||
<PackageReference Include="TagLibSharp" Version="2.2.0" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
Loading…
Reference in New Issue
Block a user