/// <summary> /// This method is executed when the user wants to play a media from an URI source. /// </summary> /// <param name="sender">The sender object's instance</param> /// <param name="e">Event parameters</param> private async void UriOpen_Click(object sender, MouseButtonEventArgs e) { this.viewModel.MenuVisible = false; #region Check requirements if (!YoutubePlayback.ToolsAvailable) { MessageBoxResult DownloadQuestion = MessageBox.Show( messageBoxText: "Első alkalommal le kell tölteni az ffmpeg.exe, az ffprobe.exe és a youtube-dl.exe programokat. Szeretnéd most letölteni?", caption: "Kellene még néhány dolog...", button: MessageBoxButton.YesNo, icon: MessageBoxImage.Question ); if (DownloadQuestion == MessageBoxResult.Yes) { ProgressBarDialog ProgressBar = new ProgressBarDialog("YouTube eszközök letöltése", "Fél perc és kész vagyunk..."); ProgressBar.Show(); await YoutubePlayback.DownloadSoftwareAsync(); ProgressBar.Close(); } else { return; } } #endregion TextInputDialog Dialog = new TextInputDialog("YouTube média letöltése", "Írd ide a videó címét, amit meg szeretnél nyitni:"); Dialog.Owner = this; bool?Result = Dialog.ShowDialog(); if (Result.HasValue && Result.Value == true) { if (!YoutubeUri.IsValidYoutubeUri(Dialog.UserInput)) { PlayerUtils.ErrorMessageBox(App.Name, "Úgy tűnik, hibás linket adtál meg."); return; } await this.OpenFilesAsync(new string[] { Dialog.UserInput }); } }
/// <summary> /// Loads the given file. /// </summary> /// <param name="Source">The file's path or an uri to load.</param> /// <returns>An <see cref="IPlaybackManager"/> instance that can handle the given file.</returns> /// <exception cref="ArgumentNullException">when <paramref name="SongInfo"/> is null</exception> /// <exception cref="NotSupportedException">when the media represented by <paramref name="SongInfo"/> is not supported by any playback methods</exception> public async static Task <IPlaybackManager> LoadMedia(ISongInfo SongInfo) { #region Error checking if (SongInfo == null) { throw new ArgumentNullException(nameof(SongInfo)); } #endregion //If the Source is file: if (File.Exists(SongInfo.Source)) { string Extension = PlayerUtils.GetFileExtension(SongInfo.Source); Progress <LongOperationProgress> FileOpenProgress = new Progress <LongOperationProgress>(); FileOpenProgress.ProgressChanged += OpenFileProgressChanged; //In case of any file supported by BASS: if (BassManager.GetSupportedExtensions().Contains(Extension)) { //If Audio CD track: if (Extension == "cda") { return(new AudioCdPlayback(SongInfo.Source)); } else { using (Stream SourceStream = File.OpenRead(SongInfo.Source)) { var unmanagedStream = await UnmanagedStream.CreateFromStream(SourceStream, FileOpenProgress); //If Midi file: if (new string[] { "mid", "midi", "kar", "rmi" }.Contains(Extension)) { return(new LocalMidiFilePlayback( unmanagedStream, SongInfo, @"C:\SGM-V2.01.sf2" )); } //Any other stuff... else { return(new LocalAudioFilePlayback( unmanagedStream, SongInfo )); } } } } } //If the Source is an Uri: else if (Uri.IsWellFormedUriString(SongInfo.Source, UriKind.Absolute)) { //Youtube link: if (SongInfo is YoutubeSongInfo) { Progress <LongOperationProgress> Progress = new Progress <LongOperationProgress>(); Progress.ProgressChanged += OpenFileProgressChanged; IPlaybackManager Result = await YoutubePlayback.DownloadVideoAsync(SongInfo, Progress); Progress.ProgressChanged -= OpenFileProgressChanged; return(Result); } } Trace.TraceWarning($"[Playback] Unsupported media: {SongInfo.Source}"); throw new NotSupportedException("Nem támogatott média"); }