private void LoadMovies() { if (MediaElement1 != null) { MediaElement1.UnloadedBehavior = MediaState.Manual; MediaElement1.MediaOpened -= MediaOpened; MediaElement1.Stop(); } if (MediaElement2 != null) { MediaElement2.UnloadedBehavior = MediaState.Manual; MediaElement2.MediaOpened -= MediaOpened; MediaElement2.Stop(); } var movieController = MediaElementController.CreateController(_movieManager, 2); MediaElement1 = movieController.MediaElements[0]; MediaElement2 = movieController.MediaElements[1]; MediaElement1.MediaOpened += MediaOpened; if (MediaElement2 != null) { MediaElement2.MediaOpened += MediaOpened; } movieController.Start(); }
private void StopButtun_Click(object sender, RoutedEventArgs e) { MediaElement1.Stop(); SeekSlider.Value = 0; PauseButton.Visibility = Visibility.Hidden; PlayButton.Visibility = Visibility.Visible; }
private void Window_Closed(object sender, EventArgs e) { MediaElement1.Close(); System.IO.FileInfo fi = new System.IO.FileInfo(System.Environment.CurrentDirectory + "\\temp.avi"); fi.Delete(); logwin.MainWin_Close(); }
private void TimelineSlider_PreviewMouseUp(object sender, MouseButtonEventArgs e) //Resumes video when you release left mouse button { MediaElement1.Play(); mDonSlider = false; TimeSpan ts = TimeSpan.FromSeconds(timelineSlider.Value); MediaElement1.Position = ts; }
private void Open_Click(object sender, RoutedEventArgs e) { aDialog.ShowDialog(); MediaElement1.Source = new Uri(aDialog.FileName); this.Name.Content = System.IO.Path.GetFileName(aDialog.FileName); MediaElement1.Play(); }
//Open new file private void Button_Click(object sender, RoutedEventArgs e) { aDialog.ShowDialog(); MediaElement1.Source = new Uri(aDialog.FileName); title.Content = aDialog.FileName.Split('\\').Last(); MediaElement1.MediaOpened += new RoutedEventHandler(mediaOpened); MediaElement1.Play(); }
void OnSongTapped(IUICommand command) { SongView songView = (SongView)command.Id; MediaElement1.Source = new Uri(songView.Location); MediaElement1.Play(); currentSong.SetSong(songView); StackPanelCurrentSong.DataContext = currentSong; }
private void Window_Drop(object sender, DragEventArgs e) { string filename = (string)((DataObject)e.Data).GetFileDropList()[0]; MediaElement1.Source = new Uri(filename); MediaElement1.LoadedBehavior = MediaState.Manual; MediaElement1.UnloadedBehavior = MediaState.Manual; MediaElement1.Play(); }
/// <summary> /// 一時停止ボタン押下イベント /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnPauseButtonClick(object sender, RoutedEventArgs args) { try { // メディア一時停止 MediaElement1.Pause(); } catch { Debug.Assert(false, MethodBase.GetCurrentMethod().Name + "で例外が発生しました"); } }
private void MediaElement1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) // play/pause on click vidio frame { if (isPlay) { MediaElement1.Pause(); isPlay = false; } else { MediaElement1.Play(); isPlay = true; } }
private void Play_Button_Click(object sender, RoutedEventArgs e) { try { MediaElement1.Stop(); } catch (Exception er) { //しょりしない logwin.AddLog(DateTime.Now, "Error: " + er.ToString()); } MediaElement1.Play(); }
void PlayPauseToggle() { if (playing) { MediaElement1.Pause(); playing = false; } else { MediaElement1.Play(); playing = true; } }
/// <summary> /// 视频开始与暂停 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button_Click(object sender, RoutedEventArgs e) { if (button.Content.ToString() == "播放") { MediaElement1.Play(); button.Content = "暂停"; getVideoName(); } else { MediaElement1.Pause(); button.Content = "播放"; getVideoName(); } }
private void PlaySong() { if (songViews.Count == 0) { return; } string location = songViews[songIndex].Location; MediaElement1.Source = new Uri(location); MediaElement1.Play(); Windows.Media.MediaControl.TrackName = songViews[songIndex].TITLE; Windows.Media.MediaControl.ArtistName = songViews[songIndex].ARTIST; currentSong.SetSong(songViews[songIndex]); StackPanelCurrentSong.DataContext = currentSong; playing = true; }
private async Task ClearTempData(string except = null) { try { MediaElement1?.Stop(); IReadOnlyList <StorageFolder> storageFolder = await knownFolder.GetFoldersAsync(); foreach (var item in storageFolder) { if (item.Name != except) { await item.DeleteAsync(StorageDeleteOption.PermanentDelete); } } } catch (Exception) { } }
void openfile() { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Video files (*.mp4)|*.mp4|All files (*.*)|*.*"; if (openFileDialog.ShowDialog() == true) { textBlock_dnd.Background = BackGround_ALPHA; textBlock_dnd.Text = ""; textBlock_dnd.IsEnabled = false; var pathToFile = openFileDialog.FileName; MediaElement1.Source = new Uri(openFileDialog.FileName); MediaElement1.Play(); isOpen = false; } }
/// <summary> /// 打开视频文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MenuItem_Click(object sender, RoutedEventArgs e) { string url = String.Empty; OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = "选择文件"; openFileDialog.Filter = "rmvb文件|*.rmvb|mp4文件|*.mp4|avi文件|*.avi|mkv文件|*.mkv"; openFileDialog.FilterIndex = 1; openFileDialog.RestoreDirectory = true; openFileDialog.DefaultExt = "rmvb"; if (openFileDialog.ShowDialog() == true) { url = openFileDialog.FileName; MediaElement1.Source = new Uri(url); MediaElement1.Play(); } }
void DropEvent(DragEventArgs e) { string[] dropContent = (string[])e.Data.GetData(DataFormats.FileDrop); pathToFile = dropContent[0].ToString(); if (pathToFile.EndsWith(".mp4")) { isOpen = false; MediaElement1.Source = new Uri(pathToFile); MediaElement1.Play(); textBlock_dnd.Text = ""; textBlock_dnd.Background = BackGround_ALPHA; } else { textBlock_dnd.Text = "\n\n\n\n\n\nFile not mp4"; textBlock_dnd.Background = BackGround_ERROR; } }
private void Button_Click_3(object sender, RoutedEventArgs e)//load { Microsoft.Win32.OpenFileDialog openf = new Microsoft.Win32.OpenFileDialog(); openf.AddExtension = true; openf.Filter = "Video Files (*.mp4)|*.mp4|Video Files (*.mpeg)|*.mpeg|Video Files (*.wmv)|*.wmv"; openf.FilterIndex = 0; openf.RestoreDirectory = true; openf.ShowDialog(); MediaElement1.Play(); try { MediaElement1.Source = new Uri(openf.FileName); } catch { new NullReferenceException("Error"); } }
private async Task SetVideo(MediaComposition mediaComposition, CancellationToken cancellationToken) { StorageFile temporaryFile = await CreateFile("Video", "temp (1)", "mp4", cancellationToken); IAsyncOperationWithProgress <TranscodeFailureReason, double> progress = mediaComposition.RenderToFileAsync(temporaryFile, MediaTrimmingPreference.Precise); CancelTask(cancellationToken); progress.Progress = new AsyncOperationProgressHandler <TranscodeFailureReason, double>(async(reason, progressInfo) => { if (cancellationToken.IsCancellationRequested) { reason.Cancel(); await ClearTempData(); } await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(async() => { ReportProgress(Stage6, Stage5ProgressBar, TextProgress5, progressInfo); if (progressInfo == 100) { Open.Content = "Browse File"; ItemSource = await GetProperties(temporaryFile, cancellationToken); Save.IsEnabled = true; } })); }); CancelTask(cancellationToken); MediaStreamSource mediaStreamSource = mediaComposition.GeneratePreviewMediaStreamSource(0, 0); MediaElement1.SetMediaStreamSource(mediaStreamSource); MediaElement1.Play(); await progress; CancelTask(cancellationToken); audioVideo.Add(temporaryFile); }
void AddToContext() { Registry.ClassesRoot.OpenSubKey("SystemFileAssociations\\.mp4", true).CreateSubKey("shell"); Registry.ClassesRoot.OpenSubKey("SystemFileAssociations\\.mp4\\shell", true).CreateSubKey("CutVideo").SetValue("", "Cut Video"); Registry.ClassesRoot.OpenSubKey("SystemFileAssociations\\.mp4\\shell\\CutVideo", true).CreateSubKey("command").SetValue("", Environment.GetCommandLineArgs()[0] + " \"%1\""); Registry.ClassesRoot.OpenSubKey("SystemFileAssociations\\.mp4\\shell\\CutVideo", true).SetValue("Icon", Environment.GetCommandLineArgs()[0]); if (Environment.GetCommandLineArgs().Length > 1) { if (Environment.GetCommandLineArgs()[1].EndsWith(".mp4")) { textBlock_dnd.Text = Environment.GetCommandLineArgs()[1].ToString(); MediaElement1.Source = new Uri(Environment.GetCommandLineArgs()[1]); MediaElement1.Play(); textBlock_dnd.Text = ""; textBlock_dnd.Background = BackGround_ALPHA; } else { textBlock_dnd.Background = BackGround_ERROR; textBlock_dnd.Text = "\n\n\n\n\nФайл неверного формата, нужон mp4"; } } }
private void BtnPause_Click(object sender, RoutedEventArgs e) { MediaElement1.Pause(); }
private void Button_Click_2(object sender, RoutedEventArgs e) { MediaElement1.Stop(); }
private void Button_Click_1(object sender, RoutedEventArgs e) { MediaElement1.Pause(); }
private void Button_Click(object sender, RoutedEventArgs e) { MediaElement1.Play(); }
private void Stop_Click(object sender, RoutedEventArgs e) { MediaElement1.Stop(); }
private void Pause_Click(object sender, RoutedEventArgs e) { //TODO check if it's playing and pause it MediaElement1.Pause(); }
//************************* Button1_EventHandler ************************************** private async void Button1_Click(object sender, RoutedEventArgs e) { //Play The sound at MediaElement1 MediaElement1.Play(); // Messagedialoge Box that pops up after the sound has played! Adapted from http://stackoverflow.com/questions/22909329/universal-apps-messagebox-the-name-messagebox-does-not-exist-in-the-current //Cretaing new dialog with message! var dialog = new MessageDialog("Did you hear the sound?"); //Title of Dialog dialog.Title = "Hear it?"; //Option buttons that appear on the MessageDialogue along with unique IDs dialog.Commands.Add(new UICommand { Label = "Yes", Id = 0 }); dialog.Commands.Add(new UICommand { Label = "No", Id = 1 }); dialog.Commands.Add(new UICommand { Label = "Play Again", Id = 3 }); var result1 = await dialog.ShowAsync(); res1 = (int)result1.Id; //if "Yes" is clicked if ((int)result1.Id == 0) { //Make Button1/MediaElement1/textBlock1 Collapsed Button1.Visibility = Visibility.Collapsed; MediaElement1.Visibility = Visibility.Collapsed; textBlock1.Visibility = Visibility.Collapsed; //Make Button2/MediaElement2/textBlock2 Visible Button2.Visibility = Visibility.Visible; MediaElement2.Visibility = Visibility.Visible; textBlock2.Visibility = Visibility.Visible; } // if "No" is clicked if ((int)result1.Id == 1) { //Make Button1/MediaElement1/textBlock1 Collapsed Button1.Visibility = Visibility.Collapsed; MediaElement1.Visibility = Visibility.Collapsed; textBlock1.Visibility = Visibility.Collapsed; //Make Button2/MediaElement2/textBlock2 Collapsed Button2.Visibility = Visibility.Collapsed; MediaElement2.Visibility = Visibility.Collapsed; textBlock2.Visibility = Visibility.Collapsed; //Make textBlockResult/SaveButton/HomeButton Visible textBlock1Result.Visibility = Visibility.Visible; SaveButton.Visibility = Visibility.Visible; HomeButton.Visibility = Visibility.Visible; } //If "Play Again" is clicked else if ((int)result1.Id == 3) { //Sound at MediaElement1 is palayed MediaElement1.Play(); //Another MessageDialog PopsUp dialog = new MessageDialog("Did you hear the sound this time?"); dialog.Title = "This time?"; dialog.Commands.Add(new UICommand { Label = "Yes", Id = 0 }); dialog.Commands.Add(new UICommand { Label = "No", Id = 1 }); result1 = await dialog.ShowAsync(); //if "Yes" is clicked if ((int)result1.Id == 0) { //Make Button1/MediaElement1/textBlock1 Collapsed Button1.Visibility = Visibility.Collapsed; MediaElement1.Visibility = Visibility.Collapsed; textBlock1.Visibility = Visibility.Collapsed; //Make Button2/MediaElement2/textBlock2 Visible Button2.Visibility = Visibility.Visible; MediaElement2.Visibility = Visibility.Visible; textBlock2.Visibility = Visibility.Visible; } // if "No" is clicked if ((int)result1.Id == 1) { //Make Button1/MediaElement1/textBlock1 Collapsed Button1.Visibility = Visibility.Collapsed; MediaElement1.Visibility = Visibility.Collapsed; textBlock1.Visibility = Visibility.Collapsed; //Make Button2/MediaElement2/textBlock2 Collapsed Button2.Visibility = Visibility.Collapsed; MediaElement2.Visibility = Visibility.Collapsed; textBlock2.Visibility = Visibility.Collapsed; //Make textBlockResult/SaveButton/HomeButton Visible textBlock1Result.Visibility = Visibility.Visible; SaveButton.Visibility = Visibility.Visible; HomeButton.Visibility = Visibility.Visible; } } }
private void Button_Click_3(object sender, RoutedEventArgs e) { MediaElement1.Stop(); Label1.Content = "Stopped....."; }
private void TimelineSlider_PreviewMouseDown(object sender, MouseButtonEventArgs e) //stops the video if you left mouse button has down on the timeline { MediaElement1.Pause(); mDonSlider = true; }