示例#1
0
        void Play(Music currentSong)
        {
            try
            {
                if (currentSong != null)
                {
                    Media.Source          = new Uri(currentSong.SongPath);
                    txtNameSongTitle.Text = currentSong.SongName;
                    txtDuration.Text      = currentSong.TotalSongTime;
                    ImageBrush imgB = new ImageBrush();
                    imgB.ImageSource = currentSong.ImgSrc;
                    Img.Fill         = imgB;

                    System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
                    dispatcherTimer.Tick    += new EventHandler(timer_Tick);
                    dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
                    dispatcherTimer.Start();
                    Media.Play();
                    currentPostion = int.Parse(currentSong.Number);
                }
            }
            catch
            {
            }
        }
 private void Play_Click(object sender, RoutedEventArgs e)
 {
     if (Media.DefaultPlaybackRate != 1)
     {
         Media.DefaultPlaybackRate = 1.0;
     }
     Media.Play();
 }
        private async void OpenFile_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker fop = new FileOpenPicker();

            fop.SuggestedStartLocation = PickerLocationId.Desktop;
            fop.ViewMode = PickerViewMode.Thumbnail;
            fop.FileTypeFilter.Add(".mp3");
            StorageFile file = await fop.PickSingleFileAsync();

            if (file != null)
            {
                IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read);

                Media.SetSource(stream, file.ContentType);
                Media.Play();
            }
        }
示例#4
0
        /// <summary>
        /// Play and pause music
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPlay_Pause_Click(object sender, RoutedEventArgs e)
        {
            if (listMusic.Count > 0)
            {
                isPlay = !isPlay;

                if (isPlay)
                {
                    btnPlay.Visibility       = Visibility.Visible;
                    btnPlay_Pause.Visibility = Visibility.Collapsed;
                    Media.Pause();
                }
                else
                {
                    btnPlay.Visibility       = Visibility.Collapsed;
                    btnPlay_Pause.Visibility = Visibility.Visible;
                    Media.Play();
                }
            }
        }