private async void ImportMedia(PinballTable table, ImportMediaType type, bool convert = false) { if (table != null) { if (table.GetType().Equals(typeof(PinballTable))) { var tempTable = table; //Store a temp version OnMediaImportStarted(tempTable); //Raise Event To Stop Videos var sourceFilePath = ImportGetSourceFilePath(table, GetFileType(type)); var destinationFilePath = ImportGetDestinationFilePath(table, type); //Exit if nothing selected if (!File.Exists(sourceFilePath)) { OnMediaImportFinished(tempTable); return; } //Convert if video if (convert && GetFileType(type) == ImportFileType.Video) { await Task.Run(() => ImportConvertFile(sourceFilePath, destinationFilePath, type)); } else { await Task.Run(() => ImportFile(sourceFilePath, destinationFilePath)); } OnMediaImportFinished(tempTable); //Raise Event To Start New Videos } } }
private string ImportGetDestinationFilePath(PinballTable table, ImportMediaType type) { switch (type) { case ImportMediaType.Playfield: return(table.Playfield.LocalPath); case ImportMediaType.Backglass: return(table.Backglass.LocalPath); case ImportMediaType.Dmd: return(table.DMD.LocalPath); case ImportMediaType.Wheel: return(table.Wheel.LocalPath); case ImportMediaType.LaunchAudio: return(table.LMusic.LocalPath); case ImportMediaType.TableAudio: return(table.LMusic.LocalPath); } return(null); }
private ImportFileType GetFileType(ImportMediaType mt) { switch (mt) { case ImportMediaType.Playfield: return(ImportFileType.Video); case ImportMediaType.Backglass: return(ImportFileType.Video); case ImportMediaType.Dmd: return(ImportFileType.Video); case ImportMediaType.Wheel: return(ImportFileType.Image); case ImportMediaType.LaunchAudio: return(ImportFileType.Audio); case ImportMediaType.TableAudio: return(ImportFileType.Audio); } return(ImportFileType.Any); }
private async void ImportConvertFile(string sourcePath, string destinationPath, ImportMediaType type) { //make directory if it doesn't exist FileUtility.CreateDirectory(Path.GetDirectoryName(destinationPath)); //Only work if source file exists if (File.Exists(sourcePath)) { //Rotate for Playfield if (type == ImportMediaType.Playfield) { await Task.Run(() => ImportConvertVideo(sourcePath, destinationPath, ConvertOptions.Rotate180)); } else { await Task.Run(() => ImportConvertVideo(sourcePath, destinationPath, ConvertOptions.None)); } } }