/// <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"); }