void _timer_Tick(object state) { this.Dispatcher.BeginInvoke(delegate() { var endSecond = (int)slider1.Value + (int)slider2.Value; var sc = new SecondsToFormattedTimeConverter(); int n = (int)MyMediaElement.Position.TotalSeconds; tbCurrentPosition.Text = (n / 60).ToString().PadLeft(2, '0') + ":" + (n % 60).ToString().PadLeft(2, '0'); if (MyMediaElement.Position.TotalSeconds >= endSecond) { MyMediaElement.Stop(); } }); }
private void Next_Click(object sender, RoutedEventArgs e) { currentIndex += 1; if (currentIndex >= ListAllSong.Count) { currentIndex = 0; } var song = ListAllSong[currentIndex]; ListViewSong.SelectedIndex = currentIndex; MyMediaElement.Source = new Uri(song.link); txtNowPlaying.Text = "Now playing: " + song.name + " - " + song.singer; MyMediaElement.Play(); }
void Play(object sender, RoutedEventArgs e) { ToggleButton tb = (ToggleButton)sender; if ((bool)tb.IsChecked) { MyMediaElement.Play(); filesPlaying = true; } else { MyMediaElement.Pause(); filesPlaying = false; } }
private async void CountDown_Completed(object sender, object e) { if (!_playingMusic) { // Start playing music var song = PickSong(); MyMediaElement.SetSource( await song.SongFile.OpenAsync(FileAccessMode.Read), song.SongFile.ContentType); // Start countdown StartCountdown(); } }
private async void CountdownFinished(object sender, object e) { if (!playmusic) { // Music Starts Playing var song = ChooseSong(); MyMediaElement.SetSource( await song.SongFile.OpenAsync(FileAccessMode.Read), song.SongFile.ContentType); // Start countdown CountdownStr(); } }
public PlayerViewModel() { TrackModelList = new ObservableCollection <TrackListModel>(); InitializeTrackList(); _timer.Interval = TimeSpan.FromMilliseconds(1000); _timer.Tick += TimerPosition; CurrentTrack = TrackModelList.First(); SelectedTrack = CurrentTrack; _trackIndex = 0; MyMediaElement.Open(new Uri(CurrentTrack.Path, UriKind.Relative)); MyMediaElement.Stop(); MyMediaElement.MediaOpened += MyMediaElementOnMediaOpened; MyMediaElement.MediaEnded += MyMediaElementOnMediaEnded; MyMediaElement.Volume = Volume; }
private void DoubleTap_PlayIcon(object sender, DoubleTappedRoutedEventArgs e) { Debug.WriteLine(ListViewSong.SelectedIndex); currentIndex = ListViewSong.SelectedIndex; if (sender is StackPanel playStackPanel) { var currentSong = playStackPanel.Tag as Song; Debug.WriteLine(currentSong.name); MyMediaElement.Source = new Uri(currentSong.link); NowPlayingText.Text = "Now playing: " + currentSong.name + " - " + currentSong.singer; } MyMediaElement.Play(); PlayAndPauseButton.Icon = new SymbolIcon(Symbol.Pause); running = true; }
private void Play(object sender, RoutedEventArgs e) { if (running) { MyMediaElement.Pause(); PlayAndPauseButton.Icon = new SymbolIcon(Symbol.Play); running = false; } else { MyMediaElement.Play(); PlayAndPauseButton.Icon = new SymbolIcon(Symbol.Pause); running = true; } }
private async void VideoImageGridView_ItemClick(object sender, ItemClickEventArgs e) { MyMediaElement.Visibility = Visibility.Visible; Images videoInContext = (Images)e.ClickedItem; StorageFolder localFolder = ApplicationData.Current.LocalFolder; StorageFile file = await localFolder.GetFileAsync(videoInContext.videoFileName); if (file != null) { IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read); MyMediaElement.SetSource(fileStream, file.ContentType); } MyMediaElement.AutoPlay = true; }
private void UIElement_OnDoubleTapped(object sender, DoubleTappedRoutedEventArgs e) { currentIndex = ListViewSong.SelectedIndex; var playIcon = sender as SymbolIcon; if (playIcon != null) { var currentSong = playIcon.Tag as Song; MyMediaElement.Source = new Uri(currentSong.link); NowPlayingText.Text = "Now playing: " + currentSong.name + " - " + currentSong.singer; } MyMediaElement.Play(); PlayAndPauseButton.Icon = new SymbolIcon(Symbol.Pause); running = true; }
private void CurrentState_Changed(object sender, RoutedEventArgs e) { MediaElement mediaElement = sender as MediaElement; if (mediaElement != null && mediaElement.IsAudioOnly == false) { if (mediaElement.CurrentState == Windows.UI.Xaml.Media.MediaElementState.Playing) { MyMediaElement.Play(); } else { MyMediaElement.Play(); } } }
private void CurrentState_Changed(object sender, RoutedEventArgs e) { MediaElement mediaElement = sender as MediaElement; if (mediaElement != null && mediaElement.IsAudioOnly == false) { if (mediaElement.CurrentState == Windows.UI.Xaml.Media.MediaElementState.Playing) { MyMediaElement.Play(); } else // CurrentState is Buffering, Closed, Opening, Paused, or Stopped. { MyMediaElement.Play(); } } }
private void PlayButton_Click(object sender, RoutedEventArgs e) { if (MyMediaElement.CurrentState == MediaElementState.Playing) { Symbol pico = Symbol.Play; SymbolIcon spico = new SymbolIcon(pico); Play.Icon = spico; MyMediaElement.Pause(); } else { Symbol pico = Symbol.Pause; SymbolIcon spico = new SymbolIcon(pico); Play.Icon = spico; MyMediaElement.Play(); } }
private void Play(object sender, RoutedEventArgs e) { if (running) { MyMediaElement.Pause(); PlayAndPauseButton.Symbol = Symbol.Play; running = false; timelineSlider.Value = timelineSlider.Value; } else { MyMediaElement.Play(); PlayAndPauseButton.Symbol = Symbol.Pause; running = true; timelineSlider.Value = timelineSlider.Value; } }
private void SpSong_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e) { Debug.WriteLine(ListViewSong.SelectedIndex); currentIndex = ListViewSong.SelectedIndex; var playIcon = sender as StackPanel; if (playIcon != null) { var currentSong = playIcon.Tag as Song; Debug.WriteLine(currentSong.name); MyMediaElement.Source = new Uri(currentSong.link); txtNowPlaying.Text = "Now playing: " + currentSong.name + " - " + currentSong.singer; } MyMediaElement.Play(); PlayAndPause.Icon = new SymbolIcon(Symbol.Pause); running = true; }
private void Previous(object sender, RoutedEventArgs e) { currentIndex -= 1; if (currentIndex < 0) { currentIndex = ListSong.Count - 1; } var song = ListSong[currentIndex]; ListViewSong.SelectedIndex = currentIndex; MyMediaElement.Source = new Uri(song.link); NowPlayingText.Text = song.name + " - " + song.singer; MyMediaElement.Play(); running = true; PlayAndPauseButton.Symbol = Symbol.Pause; img.ImageSource = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri(song.thumbnail)); }
private void VideoAnimationWindow_OnLoaded(object sender, RoutedEventArgs e) { MyMediaElement.LoadedBehavior = MediaState.Manual; MyMediaElement.MediaOpened += MyMediaElementOnMediaOpened; MyMediaElement.MediaEnded += MediaElementOnMediaEnded; MyMediaElement2.LoadedBehavior = MediaState.Manual; MyMediaElement2.MediaOpened += MyMediaElementOnMediaOpened; MyMediaElement2.MediaEnded += MediaElementOnMediaEnded2; MyMediaElement.Source = new Uri(@"AnimationPerformanceDemo\Assets\1.mp4", UriKind.RelativeOrAbsolute); MyMediaElement2.Source = new Uri(@"AnimationPerformanceDemo\Assets\2.mp4", UriKind.RelativeOrAbsolute); //await Task.Delay(_random.Next(0, 1000)); MyMediaElement.Play(); MyMediaElement2.Play(); }
private void MyMediaElementOnMediaOpenedPreview(object sender, EventArgs eventArgs) { var duration = $"{MyMediaElement.NaturalDuration.TimeSpan.Minutes}:{GetCorrectSeconds(MyMediaElement.NaturalDuration.TimeSpan.Seconds)}"; var path = MyMediaElement.Source.OriginalString; if (path == TrackModelList.Last().Path) { MyMediaElement.MediaOpened -= MyMediaElementOnMediaOpenedPreview; MyMediaElement.Open(new Uri(CurrentTrack.Path, UriKind.Relative)); MyMediaElement.Stop(); MyMediaElement.MediaOpened += MyMediaElementOnMediaOpened; MyMediaElement.MediaEnded += MyMediaElementOnMediaEnded; MyMediaElement.Volume = Volume; } TrackModelList.First(x => x.Path == path).Duration = duration; }
private void btnPlay_Click(object sender, RoutedEventArgs e) { if (MyMediaElement.CurrentState == MediaElementState.Playing) { MyMediaElement.Stop(); return; } int n = (int)slider1.Value; tbCurrentPosition.Text = (n / 60).ToString().PadLeft(2, '0') + ":" + (n % 60).ToString().PadLeft(2, '0'); if (BasicStates.CurrentState.Name != "CutRingtonePage_Playing") { VisualStateManager.GoToState(this, "CutRingtonePage_Playing", true); } var thread = new Thread(PrePlayThread); thread.Start(viewModel.CurrentSong); }
private async void VideoImageGridView_SelectionChanged(object sender, SelectionChangedEventArgs e) { var count = e.AddedItems.Count; if (count > 0) { Images videoInContext = (Images)e.AddedItems.ElementAt(count - 1); StorageFolder localFolder = ApplicationData.Current.LocalFolder; StorageFile file = await localFolder.GetFileAsync(videoInContext.videoFileName); if (file != null) { IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read); MyMediaElement.SetSource(fileStream, file.ContentType); } MyMediaElement.AutoPlay = true; } }
public void PauseSong(Song s) { IsPlay = false; PlayOrPause.Content = new Image { Source = new BitmapImage(new Uri(MediaPath.Play)) }; PlayOrPause.ToolTip = "Pause"; MyMediaElement.Pause(); if (Indicator == MediaCodes.PlayAudio) { GideonBase.SynObj.SpeakAsync("Song Paused!"); } else if (Indicator == MediaCodes.PlayVideo) { GideonBase.SynObj.SpeakAsync("Video Paused!"); } s.SongName = songname; }
private async void CountDown_CompletedAsync(object sender, object e) { if (!_playingMusic) { var song = PickSong(); MyMediaElement.SetSource (await song.SongFile.OpenAsync(FileAccessMode.Read), song.SongFile.ContentType); StartCountdown(); } else { InstructionTextBlock.Text = "Time's up, Lets just see if you could get it right"; InstructionTextBlock.Foreground = new SolidColorBrush(Colors.Green); //StartCooldown(); } }
private async void SoundGridView_Drop(object sender, DragEventArgs e) { if (e.DataView.Contains(StandardDataFormats.StorageItems)) { var items = await e.DataView.GetStorageItemsAsync(); if (items.Any()) { var storageFile = items[0] as StorageFile; var contentType = storageFile.ContentType; StorageFolder folder = ApplicationData.Current.LocalFolder; if (contentType == "audio/wav" || contentType == "audio/mpeg") { StorageFile newfile = await(storageFile.CopyAsync(folder, storageFile.Name, NameCollisionOption.GenerateUniqueName)); MyMediaElement.SetSource(await storageFile.OpenAsync(FileAccessMode.Read), contentType); MyMediaElement.Play(); } } } }
private void Media_MouseLeft(object sender, MouseButtonEventArgs e) { MyMediaElement LMediaElement = (MyMediaElement)sender; if (LMediaElement.IsSelected == false) { LMediaElement.Effect = new BlurEffect() { Radius = 10 }; LMediaElement.IsSelected = true; LMediaElement.OpacityMask = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Resources/checked.png"))); } else { LMediaElement.Effect = null; LMediaElement.IsSelected = false; LMediaElement.OpacityMask = null; } }
private void UIElement_OnDoubleTapped(object sender, DoubleTappedRoutedEventArgs e) { Debug.WriteLine(ListViewSong.SelectedIndex); currentIndex = ListViewSong.SelectedIndex; var playIcon = sender as StackPanel; if (playIcon != null) { var currentSong = playIcon.Tag as Song; Debug.WriteLine(currentSong.name); MyMediaElement.Source = new Uri(currentSong.link); NowPlayingText.Text = currentSong.name + " - " + currentSong.singer; img.ImageSource = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri(currentSong.thumbnail)); AddressBar.Visibility = Visibility.Visible; backgroud.ImageSource = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri(currentSong.thumbnail)); volumeSlider.Value = 100; } MyMediaElement.Play(); PlayAndPauseButton.Symbol = Symbol.Pause; running = true; }
private void PrePlayThread(object param) { var song = param as SongEx; string ext = song.FilePath.Substring(song.FilePath.LastIndexOf(".") + 1); if (InteropSvc.InteropLib.Instance.GetFileAttributes7("\\Applications\\Data\\9cefc0bf-7060-45b0-ba66-2d1dcad8dc3c\\Data\\IsolatedStore\\PlayingSong." + ext) != 0xFFFFFFFF) { InteropSvc.InteropLib.Instance.MoveFile7("\\Applications\\Data\\9cefc0bf-7060-45b0-ba66-2d1dcad8dc3c\\Data\\IsolatedStore\\PlayingSong." + ext, "\\Applications\\Data\\9cefc0bf-7060-45b0-ba66-2d1dcad8dc3c\\Data\\IsolatedStore\\PlayingSong2." + ext); InteropSvc.InteropLib.Instance.DeleteFile7("\\Applications\\Data\\9cefc0bf-7060-45b0-ba66-2d1dcad8dc3c\\Data\\IsolatedStore\\PlayingSong2." + ext); } bool res = InteropSvc.InteropLib.Instance.CopyFile7(song.FilePath, "\\Applications\\Data\\9cefc0bf-7060-45b0-ba66-2d1dcad8dc3c\\Data\\IsolatedStore\\PlayingSong." + ext, false); Dispatcher.BeginInvoke(delegate() { int retries = 0; L_tryAgain: try { using (IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()) using (IsolatedStorageFileStream isolatedStorageFileStream = new IsolatedStorageFileStream("PlayingSong." + ext, FileMode.Open, FileAccess.Read, FileShare.Read, isolatedStorageFile)) { MyMediaElement.SetSource(isolatedStorageFileStream); } } catch (Exception ex) { if (retries < 5) { retries++; Thread.Sleep(1000); goto L_tryAgain; } if (BasicStates.CurrentState.Name != "CutRingtonePage_Normal") { VisualStateManager.GoToState(this, "CutRingtonePage_Normal", true); } } }); }
private async void listViewArtists_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (playing) { var count = e.AddedItems.Count; if (count > 0) { Song songInContext = (Song)e.AddedItems.ElementAt(count - 1); StorageFolder localFolder = ApplicationData.Current.LocalFolder; StorageFile file = await localFolder.GetFileAsync(songInContext.SongFileName); if (file != null) { IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read); MyMediaElement.SetSource(stream, file.ContentType); } MyMediaElement.AutoPlay = true; MediaElementImage.Source = songInContext.CoverImage; } } }
private async void MyMediaElement_MediaEnded(object sender, RoutedEventArgs e) { if (isThisPageActive) { if (currentItemIndex < playlist.Count - 1) { // Current media must've been playing if we received an event about it ending. // The design of this sample scenario is to automatically start playing the next // item in the playlist. So we'll set the AutoPlay property to true, then in // SetNewMediaItem() when we eventually call SetSource() on the XAML MediaElement // control, it will automatically playing the new media item. MyMediaElement.AutoPlay = true; await SetNewMediaItem(currentItemIndex + 1); } else { // End of playlist reached. We'll just stop media playback. MyMediaElement.AutoPlay = false; MyMediaElement.Stop(); //rootPage.NotifyUser("end of playlist, stopping playback", NotifyType.StatusMessage); } } }
private async void CountDown_Completed(object sender, object e) { if (!_playingMusic) { // Start playing music var song = PickSong(); // Play the music MyMediaElement.SetSource( await song.SongFile.OpenAsync(FileAccessMode.Read), song.SongFile.ContentType); // Start countdown StartCountdown(); } else { MyMediaElement.Stop(); Song correctSong = Songs.FirstOrDefault(p => p.Selected); correctSong.Selected = false; correctSong.Used = true; DisplayCorrectSong(correctSong); int addScore = (-1) * (int)MyProgressBar.Value; _totalScore += addScore; _round++; ResultTextBlock.Text = String.Format("Score: {0}, Total Score after {1} Rounds: {2}", addScore, _round, _totalScore); if (_round >= 5) { InstructionTextBlock.Text = String.Format("Game Over... You scored: {0}", _totalScore); PlayAgainButton.Visibility = Visibility.Visible; } else { StartCooldown(); } } }
private async void SongGridView_ItemClick(object sender, ItemClickEventArgs e) { // Ignore clicks when loading new song if (!playmusic) { return; } CountDown.Pause(); MyMediaElement.Stop(); var clickedSong = (Song)e.ClickedItem; var correctSong = Songs.FirstOrDefault(p => p.Selected == true); // Correct and Incorrect answers // Produces the png pictures once right or wrong answers are clicked // A URI is used to indentify a resource in this case it is getting the images from the assets folder Uri uri; int score; if (clickedSong.Selected) { uri = new Uri("ms-appx:///Assets/correct.png"); score = (int)MyProgressBar.Value; } else { uri = new Uri("ms-appx:///Assets/incorrect.png"); score = ((int)MyProgressBar.Value) * -1; } StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uri); var fileStream = await file.OpenAsync(FileAccessMode.Read); await clickedSong.AlbumCover.SetSourceAsync(fileStream); totalScore += score; round++; //Output of scores , Correct song, Album and so on... ResultTextBlock.Text = string.Format("Score: {0} Total Score after {1} Rounds: {2}", score, round, totalScore); TitleTextBlock.Text = String.Format("Correct Song: {0}", correctSong.Title); ArtistTextBlock.Text = string.Format("Performed by: {0}", correctSong.Artist); AlbumTextBlock.Text = string.Format("On Album: {0}", correctSong.Album); clickedSong.Used = true; correctSong.Selected = false; correctSong.Used = true; if (round >= 5) { //Once game is over it will produce this message //Play Again button will also appear InstructionTextBlock.Text = string.Format("Game over ... You scored: {0}", totalScore); PlayAgainButton.Visibility = Visibility.Visible; } else { StartCooldown(); } }