1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-31 08:34:10 +02:00

Fix sound notification extension detection and add warning to mp3 files

This commit is contained in:
chylex 2018-01-14 00:08:43 +01:00
parent 6e59dfddcc
commit 2d4bbf2a6f

View File

@ -14,22 +14,29 @@ public static IResourceHandler CreateFileHandler(string path){
string mimeType;
switch(Path.GetExtension(path)){
case "weba":
case "webm": mimeType = "audio/webm"; break;
case "wav": mimeType = "audio/wav"; break;
case "ogg": mimeType = "audio/ogg"; break;
case "flac": mimeType = "audio/flac"; break;
case "opus": mimeType = "audio/ogg; codecs=opus"; break;
case ".weba":
case ".webm": mimeType = "audio/webm"; break;
case ".wav": mimeType = "audio/wav"; break;
case ".ogg": mimeType = "audio/ogg"; break;
case ".flac": mimeType = "audio/flac"; break;
case ".opus": mimeType = "audio/ogg; codecs=opus"; break;
case ".mp3": TryShowError("MP3 sound notifications are temporarily unsupported, please convert the file to another format, such as .ogg, .wav, or .flac."); return null;
default: mimeType = null; break;
}
try{
return ResourceHandler.FromFilePath(path, mimeType);
}catch{
TryShowError("Could not find custom notification sound file:\n"+path);
return null;
}
}
private static void TryShowError(string message){
FormBrowser browser = FormManager.TryFind<FormBrowser>();
browser?.InvokeAsyncSafe(() => {
using(FormMessage form = new FormMessage("Sound Notification Error", "Could not find custom notification sound file:\n"+path, MessageBoxIcon.Error)){
using(FormMessage form = new FormMessage("Sound Notification Error", message, MessageBoxIcon.Error)){
form.AddButton(FormMessage.Ignore, ControlType.Cancel | ControlType.Focused);
Button btnViewOptions = form.AddButton("View Options");
@ -41,9 +48,6 @@ public static IResourceHandler CreateFileHandler(string path){
}
}
});
return null;
}
}
}
}