Exemplo n.º 1
0
        //plays songs from a simple list.
        private async void Play_From_List(string title, List <AudioFile> listToShow)
        {
            PlaylistSongs.Items.Clear();
            SonglistView.Title = title;
            SonglistView.IsPrimaryButtonEnabled = false;
            List <StorageFile> filesToPlay = new List <StorageFile>();

            foreach (AudioFile af in listToShow)
            {
                PlaylistSongs.Items.Add(af);
                StorageFile sf = await StorageFile.GetFileFromPathAsync(af.Path);

                filesToPlay.Add(sf);
            }
            PlaylistSongs.CanDragItems    = false;
            PlaylistSongs.CanReorderItems = false;
            PlaylistSongs.AllowDrop       = false;
            ContentDialogResult result = await SonglistView.ShowAsync();

            if (result == ContentDialogResult.Secondary)
            {
                MediaPlaybackList mediaPlaybackList = new MediaPlaybackList();
                queue.Clear();
                foreach (var f in filesToPlay)
                {
                    var af = songFileList.Where(sf => sf.Name == f.Name).FirstOrDefault();
                    queue.Add(af);
                    mediaPlaybackList.Items.Add(new MediaPlaybackItem(MediaSource.CreateFromStorageFile(f)));
                }
                if (mediaPlaybackList.Items.Count != 0)
                {
                    mediaElement.Source = mediaPlaybackList;
                    mediaPlaybackList.CurrentItemChanged += new TypedEventHandler <MediaPlaybackList, CurrentMediaPlaybackItemChangedEventArgs>(Track_Changes);
                    mediaElement.MediaPlayer.Play();
                    currentPlaying = -1;
                }
            }
        }
Exemplo n.º 2
0
        //Handels commadbar button click event for queue button.
        private async void QueueButton_Click(object sender, RoutedEventArgs e)
        {
            PlaylistSongs.Items.Clear();
            foreach (AudioFile af in queue)
            {
                PlaylistSongs.Items.Add(af);
            }
            PlaylistSongs.SelectedIndex         = currentPlaying;
            PlaylistSongs.CanDragItems          = true;
            PlaylistSongs.CanReorderItems       = true;
            PlaylistSongs.AllowDrop             = true;
            SonglistView.IsPrimaryButtonEnabled = true;
            SonglistView.PrimaryButtonText      = "Save";
            ContentDialogResult result = await SonglistView.ShowAsync();

            if (result == ContentDialogResult.Primary)
            {
                queue.Clear();
                foreach (AudioFile af in PlaylistSongs.Items)
                {
                    queue.Add(af);
                }
            }
        }
Exemplo n.º 3
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);
            }
        }