예제 #1
0
        public static async Task <MediaPlaybackItem> ToMediaItem(MusicItem m)
        {
            var file = await StorageFile.GetFileFromPathAsync(m.FilePath);

            var stream = await file.OpenAsync(FileAccessMode.Read);

            var source = MediaSource.CreateFromStream(stream, file.ContentType);

            source.CustomProperties["FilePath"]       = m.FilePath;
            source.CustomProperties["CoverImagePath"] = m.CoveImagePath;
            source.CustomProperties["Title"]          = m.Title;
            source.CustomProperties["Artist"]         = m.Artist;
            source.CustomProperties["Album"]          = m.Album;
            var item = new MediaPlaybackItem(source);

            var displayproperties = item.GetDisplayProperties();

            displayproperties.Type = MediaPlaybackType.Music;
            displayproperties.MusicProperties.Title      = m.Title;
            displayproperties.MusicProperties.Artist     = m.Artist;
            displayproperties.MusicProperties.AlbumTitle = m.Album;
            if (m.CoveImagePath != null)
            {
                displayproperties.Thumbnail = RandomAccessStreamReference.CreateFromUri(new Uri(m.CoveImagePath));
            }
            item.ApplyDisplayProperties(displayproperties);

            return(item);
        }
예제 #2
0
        public async static void Play(MusicItem m)
        {
            var media = await ToMediaItem(m);

            NowPlayingList.Items.Clear();
            NowPlayingList.Items.Add(media);
            Player.Play();

            //Update mtc playlist
            MainPage mp = (Window.Current.Content as Frame).Content as MainPage;

            mp.UpdateNowplayingListViewSource();
        }
예제 #3
0
        public async static void AddToNowPlaying(MusicItem m)
        {
            //check
            if (NowPlayingList.Items.Count == 0)
            {
                NowPlayingList.CurrentItemChanged += NowPlayingList_CurrentItemChanged1;
            }
            var media = await ToMediaItem(m);

            NowPlayingList.Items.Add(media);
            Player.Play();
            Player.SystemMediaTransportControls.IsNextEnabled = true;

            //Update mtc playlist
            MainPage mp = (Window.Current.Content as Frame).Content as MainPage;

            mp.UpdateNowplayingListViewSource();
        }