示例#1
0
        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();
                    }
                }
            }
        }
示例#2
0
        //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);
            }
        }