예제 #1
0
 private void Pause()
 {
     ControlLabel.Text = "Pause";
     MyMediaPlayer.Pause();
     StatusButton.Icon = new SymbolIcon(Symbol.Play);
     _isPlaying        = false;
 }
예제 #2
0
 private void Play()
 {
     MyMediaPlayer.Source       = new Uri(_songs[_currentIndex].link);
     ControlLabel.Text          = "Now Playing: " + _songs[_currentIndex].name;
     ListViewSong.SelectedIndex = _currentIndex;
     MyMediaPlayer.Play();
     StatusButton.Icon = new SymbolIcon(Symbol.Pause);
     _isPlaying        = true;
 }
예제 #3
0
        //粤语发音
        private async void Voice_Click(object sender, RoutedEventArgs e)
        {
            TextToVoice temp  = new TextToVoice();
            Stream      voice = await temp.ReadText(Input.Text);

            InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream();
            await voice.CopyToAsync(ras.AsStreamForWrite());

            await ras.FlushAsync();

            ras.Seek(0);
            MyMediaPlayer.SetSource(ras, "");
        }
예제 #4
0
        private void ListViewSong_OnDoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
        {
            var selectItem = ListViewSong.SelectedItem as Song;

            MyMediaPlayer.Pause();
            if (selectItem != null)
            {
                _currentIndex             = _songs.IndexOf(selectItem);
                MyMediaPlayer.Source      = new Uri(selectItem.link);
                SongThumbnail.ImageSource = new BitmapImage(new Uri(selectItem.thumbnail));
                Play();
            }
        }
예제 #5
0
        private void SelectSong(object sender, TappedRoutedEventArgs e)
        {
            var selectItem = sender as StackPanel;

            MyMediaPlayer.Pause();
            {
                if (selectItem.Tag is Song currentSong)
                {
                    _currentIndex        = _mysongs.IndexOf(currentSong);
                    MyMediaPlayer.Source = new Uri(currentSong.link);
                    Play();
                }
            }
        }
예제 #6
0
        private void SelectSong(object sender, TappedRoutedEventArgs e)
        {
            var selectItem = sender as TextBlock;

            MyMediaPlayer.Pause();
            if (selectItem != null)
            {
                if (selectItem.Tag is Song currentSong)
                {
                    _currentIndex        = _songs.IndexOf(currentSong);
                    MyMediaPlayer.Source = new Uri(currentSong.link);
                    Play();
                }
            }
        }
예제 #7
0
        private void SelectSong(object sender, TappedRoutedEventArgs e)
        {
            var selectItem = sender as StackPanel;

            MyMediaPlayer.Pause();
            if (selectItem != null)
            {
                if (selectItem.Tag is Music currentSong)
                {
                    Debug.WriteLine("Tag of selectItem: " + selectItem.Tag);

                    _currentIndex        = listMusic.IndexOf(currentSong);
                    MyMediaPlayer.Source = new Uri(currentSong.link);
                    Play();
                }
            }
        }
예제 #8
0
        async private System.Threading.Tasks.Task SetLocalMedia()
        {
            var openPicker = new Windows.Storage.Pickers.FileOpenPicker();

            openPicker.FileTypeFilter.Add(".mp4");
            openPicker.FileTypeFilter.Add(".mp3");

            var file = await openPicker.PickSingleFileAsync();

            // mediaPlayer is a MediaElement defined in XAML
            if (file != null)
            {
                var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                MyMediaPlayer.SetSource(stream, file.ContentType);

                MyMediaPlayer.Play();
            }
        }
예제 #9
0
 private void PlayPauseButton_Click(object sender, RoutedEventArgs e)
 {
     if (PlayPauseButton.Content.ToString() == "\xE768")
     {
         PlayPauseButton.Content = "\xE769";
         if (RunningTime != TotalTime)
         {
             MyMediaPlayer.Position = RunningTime;
             timerPlayTime.Start();
             MyMediaPlayer.Play();
         }
     }
     else if (PlayPauseButton.Content.ToString() == "\xE769")
     {
         PlayPauseButton.Content = "\xE768";
         MyMediaPlayer.Stop();
         timerPlayTime.Stop();
     }
 }
예제 #10
0
        private async void SoundGridView_Drop(object sender, DragEventArgs e)
        {
            if (e.DataView.Contains(StandardDataFormats.StorageItems))
            {
                var items = await e.DataView.GetStorageItemsAsync();

                if (items.Any())
                {
                    StorageFile storageFile = items[0] as StorageFile;
                    var         contentType = storageFile.ContentType;

                    if (contentType == "audio/mpeg" || contentType == "audio/wav")
                    {
                        MyMediaPlayer.SetSource(await storageFile.OpenAsync(FileAccessMode.Read), contentType);
                        MyMediaPlayer.Play();
                        PlayPauseButton.Content = "\xE769";
                    }
                }
            }
        }
예제 #11
0
        //   [Obsolete]//Attribute("Obsolete Function used")
        private void  SongsGridView_ItemClick(object sender, ItemClickEventArgs e)
        {
            //var s = e.ClickedItem as StorageFile;
            var clickedSong = (Song)e.ClickedItem;

            //MyMediaPlayer.Source = clickedSong.SongFile.OpenReadAsync();
            //MyMediaPlayer.Source=(await clickedSong.SongFile.OpenAsync(FileAccessMode.Read), clickedSong.SongFile.ContentType);
            //MyMediaElement.SetSource(await song.SongFile.OpenAsync(FileAccessMode.Read), song.SongFile.ContentType);

            foreach (var item in Songs)
            {
                if (clickedSong.Title == item.Title)
                {
                    //MyMediaPlayer.MediaPlayer.SetStreamSource(await item.SongFile.OpenAsync(FileAccessMode.Read));
                    //MyMediaPlayer.MediaPlayer.source

                    _mediaSource        = MediaSource.CreateFromStorageFile(item.SongFile);
                    _mediaPlayer        = new MediaPlayer();
                    _mediaPlayer.Source = _mediaSource;
                    MyMediaPlayer.SetMediaPlayer(_mediaPlayer);

                    //  MyMediaPlayer.MediaPlayer.SetFileSource((IStorageFile)item.SongFile);

                    //          MyMediaPlayer.MediaPlayer.SetFileSource(await item.SongFile.OpenAsync(FileAccessMode.Read), item.SongFile.ContentType);
                    //      MyMediaPlayer.MediaPlayer.SetStreamSource(await item.SongFile.OpenAsync(FileAccessMode.Read));
                    //    MyMediaPlayer.MediaPlayer.SetFileSource(item.SongFile);
                    //    MyMediaPlayer.MediaPlayer.SetStreamSource((await clickedSong.SongFile.OpenAsync(FileAccessMode.Read), clickedSong.SongFile.ContentType));
                    // MyMediaPlayer.Source =await item.SongFile.OpenReadAsync();

                    //===============================Set Media Background later
                    //var brush = new SolidColorBrush();
                    //= item.AlbumCover.UriSource;
                    //MyMediaPlayer.MediaPlayer.= item.AlbumCover;
                    MyMediaPlayer.PosterSource = item.AlbumCover;
                    MyMediaPlayer.MediaPlayer.Play();
                }
            }
        }
예제 #12
0
        private async void DownLoadButton_Click(object sender, RoutedEventArgs e)
        {
            Uri uri = new Uri(MyBox.Text);

            MyMediaPlayer.Source = uri;
            string FileName = System.IO.Path.GetFileName(uri.LocalPath);


            var httpClient   = new HttpClient();
            var httpResponse = new Windows.Web.Http.HttpResponseMessage();
            var file         = await KnownFolders.MusicLibrary.CreateFileAsync(FileName, CreationCollisionOption.ReplaceExisting);

            string httpResponseBody = "";

            try
            {
                httpResponse = await httpClient.GetAsync(uri);

                httpResponse.EnsureSuccessStatusCode();
                httpResponseBody = await httpResponse.Content.ReadAsStringAsync();

                var sourceStream = await httpResponse.Content.ReadAsInputStreamAsync();

                using (var destinationStream = await file.OpenAsync(FileAccessMode.ReadWrite))
                {
                    using (var destinationOutputStream = destinationStream.GetOutputStreamAt(0))
                    {
                        await RandomAccessStream.CopyAndCloseAsync(sourceStream, destinationStream);
                    }
                }
                var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                MyMediaPlayer.SetSource(stream, file.ContentType);
                MyMediaPlayer.Play();
            }
            catch { }
        }
 protected override void OnNavigatedFrom(NavigationEventArgs e)
 {
     MyMediaPlayer.Pause();
 }
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     base.OnNavigatedTo(e);
     MyMediaPlayer.Play();
 }