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

Ogg audiofile can not be used #316

Merged
merged 2 commits into from
Mar 26, 2024
Merged
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
2 changes: 1 addition & 1 deletion AudioCuesheetEditor/Model/IO/Audio/Audiofile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Audiofile(String name, Boolean isRecorded = false)
IsRecorded = isRecorded;
}

public Audiofile(String name, String objectURL, AudioCodec audioCodec, HttpClient httpClient, Boolean isRecorded = false) : this(name, isRecorded)
public Audiofile(String name, String objectURL, AudioCodec? audioCodec, HttpClient httpClient, Boolean isRecorded = false) : this(name, isRecorded)
{
if (String.IsNullOrEmpty(objectURL))
{
Expand Down
2 changes: 1 addition & 1 deletion AudioCuesheetEditor/Model/UI/TraceChangeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ private void Traceable_TraceablePropertyChanged(object? sender, TraceablePropert
if (BulkEdit == false)
{
//Single change
var changes = new TracedChanges(new List<TracedChange>() { new TracedChange((ITraceable)sender, e.TraceableChange) });
var changes = new TracedChanges(new List<TracedChange>() { new((ITraceable)sender, e.TraceableChange) });
undoStack.Push(changes);
redoStack.Clear();
TracedObjectHistoryChanged?.Invoke(this, EventArgs.Empty);
Expand Down
26 changes: 19 additions & 7 deletions AudioCuesheetEditor/Model/Utility/IOUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,28 @@ public static Boolean CheckFileMimeType(IFileEntry file, String mimeType, String
return fileMimeTypeMatches;
}

public static Boolean CheckFileMimeType(IFileEntry file, IReadOnlyCollection<AudioCodec> audioCodecs)
public static Boolean CheckFileMimeTypeForAudioCodec(IFileEntry file)
{
Boolean fileMimeTypeMatches = false;
if ((file != null) && (audioCodecs != null))
return GetAudioCodec(file) != null;
}

public static AudioCodec? GetAudioCodec(IFileEntry fileEntry)
{
AudioCodec? foundAudioCodec = null;
var extension = Path.GetExtension(fileEntry.Name).ToLower();
// First search with mime type and file extension
var audioCodecsFound = Audiofile.AudioCodecs.Where(x => x.MimeType.Equals(fileEntry.Type, StringComparison.OrdinalIgnoreCase) && x.FileExtension.Equals(extension, StringComparison.OrdinalIgnoreCase));
if (audioCodecsFound.Count() <= 1)
{
var extension = Path.GetExtension(file.Name).ToLower();
var audioCodecsFound = audioCodecs.Where(x => x.MimeType.Equals(file.Type, StringComparison.OrdinalIgnoreCase) || x.FileExtension.Equals(extension, StringComparison.OrdinalIgnoreCase));
fileMimeTypeMatches = (audioCodecsFound != null) && (audioCodecsFound.Any());
foundAudioCodec = audioCodecsFound.FirstOrDefault();
}
return fileMimeTypeMatches;
else
{
// Second search with mime type or file extension
audioCodecsFound = Audiofile.AudioCodecs.Where(x => x.MimeType.Equals(fileEntry.Type, StringComparison.OrdinalIgnoreCase) || x.FileExtension.Equals(extension, StringComparison.OrdinalIgnoreCase));
foundAudioCodec = audioCodecsFound.FirstOrDefault();
}
return foundAudioCodec;
}
}
}
6 changes: 3 additions & 3 deletions AudioCuesheetEditor/Pages/ViewModeImport.razor
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ along with Foobar. If not, see
if ((IOUtility.CheckFileMimeType(file, Projectfile.MimeType, Projectfile.FileExtension) == false)
&& (IOUtility.CheckFileMimeType(file, Cuesheet.MimeType, Cuesheet.FileExtension) == false)
&& (IOUtility.CheckFileMimeType(file, TextImportfile.MimeType, TextImportfile.FileExtension) == false)
&& (IOUtility.CheckFileMimeType(file, Audiofile.AudioCodecs) == false))
&& (IOUtility.CheckFileMimeTypeForAudioCodec(file) == false))
{
invalidDropFileNames.Add(file.Name);
}
Expand Down Expand Up @@ -528,10 +528,10 @@ along with Foobar. If not, see
_sessionStateContainer.TextImportFile.TimeSpanFormat.ValidateablePropertyChanged += Timespanformat_ValidateablePropertyChanged;
_sessionStateContainer.TextImportFile.TextImportScheme.ValidateablePropertyChanged += TextImportScheme_ValidateablePropertyChanged;
}
if (IOUtility.CheckFileMimeType(file, Audiofile.AudioCodecs) == true)
if (IOUtility.CheckFileMimeTypeForAudioCodec(file) == true)
{
var audioFileObjectURL = await _jsRuntime.InvokeAsync<String>("getObjectURL", "dropFileInput");
var codec = Audiofile.AudioCodecs.Single(x => x.MimeType.Equals(file.Type, StringComparison.OrdinalIgnoreCase));
var codec = IOUtility.GetAudioCodec(file);
var audiofile = new Audiofile(file.Name, audioFileObjectURL, codec, _httpClient);
_ = audiofile.LoadContentStream();
_sessionStateContainer.ImportAudiofile = audiofile;
Expand Down
4 changes: 2 additions & 2 deletions AudioCuesheetEditor/Shared/CuesheetData.razor
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ along with Foobar. If not, see
if (Cuesheet != null)
{
var file = e.Files.First();
if (IOUtility.CheckFileMimeType(file, Audiofile.AudioCodecs) == true)
if (IOUtility.CheckFileMimeTypeForAudioCodec(file) == true)
{
await SetAudioFile(file);
}
Expand Down Expand Up @@ -262,7 +262,7 @@ along with Foobar. If not, see
if (file != null)
{
var audioFileObjectURL = await _jsRuntime.InvokeAsync<String>("getObjectURL", fileEditAudiofileId);
var codec = Audiofile.AudioCodecs.Single(x => x.MimeType.Equals(file.Type, StringComparison.OrdinalIgnoreCase));
var codec = IOUtility.GetAudioCodec(file);
var audiofile = new Audiofile(file.Name, audioFileObjectURL, codec, _httpClient);
_ = audiofile.LoadContentStream();
Cuesheet.Audiofile = audiofile;
Expand Down
Loading