//When adding a song to new playlist. private async void NewPlaylist_click(object sender, RoutedEventArgs e) { var buttonTag = ((Button)sender).Tag.ToString(); Debug.WriteLine(buttonTag); PlaylistList.Items.Clear(); ContentDialogResult result = await NewPlayListDialog.ShowAsync(); if (result == ContentDialogResult.Primary) { Windows.Media.Playlists.Playlist playlist = new Windows.Media.Playlists.Playlist(); StorageFolder sf = KnownFolders.MusicLibrary; string name = PlaylistName.Text; NameCollisionOption collisionOption = NameCollisionOption.ReplaceExisting; PlaylistFormat format = PlaylistFormat.WindowsMedia; StorageFile storageFile = await StorageFile.GetFileFromPathAsync(buttonTag); playlist.Files.Add(storageFile); try { StorageFile savedFile = await playlist.SaveAsAsync(sf, name, collisionOption, format); LoadPlaylistsView(); LoadPlaylists(); } catch (Exception error) { Debug.WriteLine(error.StackTrace); } } }
/// <summary> /// Creates a playlist with the audio picked by the user in the FilePicker /// </summary> /// <param name="sender"></param> /// <param name="e"></param> async private void PickAudioButton_Click(object sender, RoutedEventArgs e) { FileOpenPicker picker = MainPage.CreateFilePicker(MainPage.audioExtensions); IReadOnlyList <StorageFile> files = await picker.PickMultipleFilesAsync(); if (files.Count > 0) { Playlist playlist = new Playlist(); foreach (StorageFile file in files) { playlist.Files.Add(file); } StorageFolder folder = KnownFolders.MusicLibrary; string name = "Sample"; NameCollisionOption collisionOption = NameCollisionOption.ReplaceExisting; PlaylistFormat format = PlaylistFormat.WindowsMedia; try { StorageFile savedFile = await playlist.SaveAsAsync(folder, name, collisionOption, format); this.rootPage.NotifyUser(savedFile.Name + " was created and saved with " + files.Count + " files.", NotifyType.StatusMessage); } catch (Exception error) { rootPage.NotifyUser(error.Message, NotifyType.ErrorMessage); } } else { rootPage.NotifyUser("No files picked.", NotifyType.ErrorMessage); } }
public void GeneratePlaylistEvent(PlaylistFormat format) { SendEvent( FirebaseAnalytics.Event.SelectContent, Category_Generate, Action_Generate_Playlist, Action_Generate_Playlist + Seperator + format.ToString(), null ); }
/// <summary> /// create the correct playlist format /// </summary> /// <param name="playlistFormat">the playlist format required</param> /// <param name="fileName">filename to use for the playlist</param> /// <returns></returns> public IPlaylist CreatePlaylist(PlaylistFormat playlistFormat, string fileName) { switch (playlistFormat) { case PlaylistFormat.ASX: return(new PlaylistAsx(fileName, true)); case PlaylistFormat.WPL: return(new PlaylistWpl(fileName, true)); } throw new EnumOutOfRangeException("playlistFormat"); }
/// <summary> /// Gets the playlist. /// </summary> /// <returns>The playlist.</returns> public string GetPlaylist(PlaylistFormat format) { switch (format) { case PlaylistFormat.M3U8: return(this.GetM3U8Playlist()); case PlaylistFormat.PLS: return(this.GetPLSPlaylist()); default: throw new NotImplementedException("Generate a playlist in this format isn't implemented."); } }
public void PLIO_Format_Init() { PlaylistFormat tempFmt = new PlaylistFormat(0, "M3U"); tempFmt.AddMimeType("blah"); tempFmt.AddExtension(".m3u"); PlaylistFormat testFmt = new PlaylistFormat(tempFmt); Assert.AreEqual(tempFmt.ID, testFmt.ID); Assert.AreEqual(tempFmt.Name, testFmt.Name); Assert.AreEqual(tempFmt.LocationFormat, testFmt.LocationFormat); Assert.AreEqual(tempFmt.MimeList.Count, testFmt.MimeList.Count); Assert.AreEqual(tempFmt.Readable, testFmt.Readable); }
private static string WritePlaylistFormat(PlaylistFormat playlistFormat) { switch (playlistFormat) { case PlaylistFormat.ASX: return("asx"); case PlaylistFormat.WPL: return("wpl"); case PlaylistFormat.Unknown: return("unknown"); default: throw new ArgumentOutOfRangeException("playlistFormat"); } }
//When adding a song to existing playlist. private async void ExistingPlaylist_Click(object sender, RoutedEventArgs e) { var buttonTag = ((Button)sender).Tag.ToString(); Debug.WriteLine("Inside dialog:"); PlaylistList.Items.Clear(); foreach (var v in PlaylistsList) { v.Name = v.Name.Substring(0, v.Name.LastIndexOf('.')); PlaylistList.Items.Add(v); Debug.WriteLine(v.Name); } Debug.WriteLine("Ends for loop:"); ExistingPlayListDialog.IsPrimaryButtonEnabled = false; ContentDialogResult result = await ExistingPlayListDialog.ShowAsync(); if (result == ContentDialogResult.Primary) { Windows.Media.Playlists.Playlist playlist = new Windows.Media.Playlists.Playlist(); StorageFolder sf = KnownFolders.MusicLibrary; IReadOnlyList <StorageFile> fileList = await sf.GetFilesAsync(); var playlistFile = fileList.Where(f => f.Name == clickedPlaylist.Name).FirstOrDefault(); playlist = await Windows.Media.Playlists.Playlist.LoadAsync(playlistFile); NameCollisionOption collisionOption = NameCollisionOption.ReplaceExisting; PlaylistFormat format = PlaylistFormat.WindowsMedia; StorageFile storageFile = await StorageFile.GetFileFromPathAsync(buttonTag); playlist.Files.Add(storageFile); try { StorageFile savedFile = await playlist.SaveAsAsync(sf, playlistFile.Name.Replace(".wpl", ""), collisionOption, format); Debug.WriteLine("Edited successfully"); } catch (Exception error) { Console.WriteLine(error.StackTrace); Debug.WriteLine("Something went wrong:" + error.StackTrace); } } }
private async void CreateClicked(object sender, RoutedEventArgs e) { if (StandardPopup.IsOpen) { StandardPopup.IsOpen = false; } Playlist playlist = new Playlist(); StorageFolder sf = KnownFolders.MusicLibrary; string name = PlayListName.Text; NameCollisionOption collisionOption = NameCollisionOption.ReplaceExisting; PlaylistFormat format = PlaylistFormat.WindowsMedia; try { StorageFile savedFile = await playlist.SaveAsAsync(sf, name, collisionOption, format); } catch (Exception error) { Console.WriteLine(error.StackTrace); } }
/// <summary> /// Instanciate a new PlaylistFormat by copying the given PlaylistFormat's attributes /// </summary> /// <param name="f">PlaylistFormat object to copy attributes from</param> public PlaylistFormat(PlaylistFormat f) : base(f) { }
/// <summary> /// the format for the generated playlist /// </summary> public void SetPlaylistFormat(PlaylistFormat value) { PlaylistFormat = value; }
private async void PlaylistList_ItemClick(object sender, ItemClickEventArgs e) { PlaylistSongs.Items.Clear(); const ThumbnailMode thumbnailMode = ThumbnailMode.MusicView; Model.Playlist playlistToShow = (Model.Playlist)e.ClickedItem; var fileToShow = fileList.Where(f => f.Name == playlistToShow.Name).FirstOrDefault(); Playlist playlist = await Playlist.LoadAsync(fileToShow); foreach (var s in playlist.Files) { const uint size = 100; using (StorageItemThumbnail thumbnail = await s.GetThumbnailAsync(thumbnailMode, size)) { // Also verify the type is ThumbnailType.Image (album art) instead of ThumbnailType.Icon // (which may be returned as a fallback if the file does not provide album art) if (thumbnail != null && thumbnail.Type == ThumbnailType.Image) { BitmapImage bitmapImage = new BitmapImage(); bitmapImage.SetSource(thumbnail); Model.MediaFile o1 = new Model.AudioFile(); Image i = new Image(); MusicProperties musicProperties = await s.Properties.GetMusicPropertiesAsync(); i.Source = bitmapImage; o1.Thumb = i; o1.Title = s.Name; if (musicProperties.Title != "") { o1.Title = musicProperties.Title; } o1.Name = s.Name; o1.Path = "MusicLibrary"; PlaylistSongs.Items.Add(o1); } } } PlaylistView.Title = fileToShow.Name.Replace(".wpl", ""); ContentDialogResult contentDialogResult = await PlaylistView.ShowAsync(); if (contentDialogResult == ContentDialogResult.Primary) { playlist.Files.Clear(); StorageFolder sf = KnownFolders.MusicLibrary; NameCollisionOption collisionOption = NameCollisionOption.ReplaceExisting; PlaylistFormat format = PlaylistFormat.WindowsMedia; foreach (Model.MediaFile item in PlaylistSongs.Items) { StorageFile storageFile = await sf.GetFileAsync(item.Name); playlist.Files.Add(storageFile); Debug.WriteLine(item.Name); } StorageFile savedFile = await playlist.SaveAsAsync(sf, fileToShow.Name.Replace(".wpl", ""), collisionOption, format); } else if (contentDialogResult == ContentDialogResult.Secondary) { if (fileToShow != null) { Playlist playlistToPlay = await Playlist.LoadAsync(fileToShow); MediaPlaybackList mediaPlaybackList = new MediaPlaybackList(); foreach (var f in playlist.Files) { mediaPlaybackList.Items.Add(new MediaPlaybackItem(MediaSource.CreateFromStorageFile(f))); } if (mediaPlaybackList.Items.Count != 0) { mediaElement.Source = mediaPlaybackList; mediaElement.MediaPlayer.Play(); } } } }
//Handels playlist list item click event to show songds of the playlist in dialog box. private async void PlaylistList_ItemClick(object sender, ItemClickEventArgs e) { queue.Clear(); PlaylistSongs.Items.Clear(); const ThumbnailMode thumbnailMode = ThumbnailMode.MusicView; Model.Playlist playlistToShow = (Model.Playlist)e.ClickedItem; var fileToShow = fileList.Where(f => f.Name == playlistToShow.Name).FirstOrDefault(); Windows.Media.Playlists.Playlist playlist = await Windows.Media.Playlists.Playlist.LoadAsync(fileToShow); foreach (var s in playlist.Files) { var af = songFileList.Where(sf => sf.Name == s.Name).FirstOrDefault(); const uint size = 100; using (StorageItemThumbnail thumbnail = await s.GetThumbnailAsync(thumbnailMode, size)) { if (thumbnail != null && (thumbnail.Type == ThumbnailType.Image || thumbnail.Type == ThumbnailType.Icon)) { BitmapImage bitmapImage = new BitmapImage(); bitmapImage.SetSource(thumbnail); Model.MediaFile o1 = new Model.AudioFile(); Image i = new Image(); MusicProperties musicProperties = await s.Properties.GetMusicPropertiesAsync(); i.Source = bitmapImage; o1.Thumb = i; o1.Title = s.Name; if (musicProperties.Title != "") { o1.Title = musicProperties.Title; } o1.Name = s.Name; o1.Path = s.Path; PlaylistSongs.Items.Add(o1); } } } SonglistView.Title = fileToShow.Name.Replace(".wpl", ""); SonglistView.IsPrimaryButtonEnabled = true; SonglistView.PrimaryButtonText = "Save"; PlaylistSongs.CanDragItems = true; PlaylistSongs.CanReorderItems = true; PlaylistSongs.AllowDrop = true; ContentDialogResult contentDialogResult = await SonglistView.ShowAsync(); if (contentDialogResult == ContentDialogResult.Primary) { playlist.Files.Clear(); StorageFolder sf = KnownFolders.MusicLibrary; NameCollisionOption collisionOption = NameCollisionOption.ReplaceExisting; PlaylistFormat format = PlaylistFormat.WindowsMedia; foreach (Model.MediaFile item in PlaylistSongs.Items) { StorageFile storageFile = await StorageFile.GetFileFromPathAsync(item.Path); playlist.Files.Add(storageFile); Debug.WriteLine(item.Name); } StorageFile savedFile = await playlist.SaveAsAsync(sf, fileToShow.Name.Replace(".wpl", ""), collisionOption, format); } else if (contentDialogResult == ContentDialogResult.Secondary) { Play_From_Playlist(playlistToShow.Name); } }
static public Track Parse(string Line, PlaylistFormat Format) { switch (Format) { case PlaylistFormat.Auto: throw new ArgumentException("Format recognition is not supported at track level."); case PlaylistFormat.Internal: string State = Line.Substring(0, 1); string Path = System.IO.Path.GetFullPath(Line.Substring(2)); Track Track = new Track(Path); switch (State) { case "Q": Track._Result = TrackResult.None; break; case "A": Track._Result = TrackResult.Aborted; break; case "D": Track._Result = TrackResult.Success; break; case "S": Track._Result = TrackResult.None; Track._Excluded = true; break; default: Track._Result = TrackResult.Error; break; } return Track; case PlaylistFormat.M3U: try { string[] Lines = Line.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); Track M3UTrack = new Track(System.IO.Path.GetFullPath(Lines[1].Trim().Trim(new char[] { '\r' }))); M3UTrack._Result = TrackResult.None; return M3UTrack; } catch { throw new ArgumentException("The specified playlist line could not be recognized."); } } throw new ArgumentException("The specified playlist format is not supported."); }
public string ToString(PlaylistFormat Format) { switch (Format) { case PlaylistFormat.Auto: throw new ArgumentException("A format must be specified."); case PlaylistFormat.Internal: string State; switch (this.State) { case TrackState.Queued: State = "Q"; break; case TrackState.Playing: case TrackState.Paused: if ((double)this.Position / (double)this.Length < 0.38D) { State = "Q"; } else { State = "A"; } break; case TrackState.Fading: if (this._Fade.Type == FadeType.End) { State = "D"; } else { State = "A"; } break; case TrackState.Excluded: State = "S"; break; case TrackState.Aborted: State = "A"; break; case TrackState.Done: State = "D"; break; case TrackState.Error: State = "E"; break; default: State = "E"; break; } return State + " " + this.File; case PlaylistFormat.M3U: return "#EXTINF:" + (this._InfoAvailable ? this.Length.ToString() : "0") + "," + (this._InfoAvailable ? this.Name : Path.GetFileNameWithoutExtension(this.File)) + "\n" + this.File; } throw new ArgumentException("The specified playlist format is not supported."); }
public ControlFileMocker ApplyPlaylistFormat(PlaylistFormat format) { A.CallTo(() => MockControlFile.GetPlaylistFormat()).Returns(format); return(this); }