private async void OpenVideoFileAndPlay(StorageFile videoFile) { var videoStream = await videoFile.OpenAsync(FileAccessMode.Read); VideoElement.SetSource(videoStream, videoFile.ContentType); nameBlock.Text = videoFile.DisplayName; }
private async void Commands_LoadMedia(object sender, ExecutedRoutedEventArgs e) { Command_UnloadMedia(null, null); CommonOpenFileDialog fileDialog = new CommonOpenFileDialog { Title = "打开媒体文件", DefaultDirectory = Environment.CurrentDirectory, IsFolderPicker = false, AllowNonFileSystemItems = true, EnsurePathExists = true, Multiselect = false, //Filters = { new CommonFileDialogFilter("波形音频", ".wav") }, EnsureFileExists = true }; if (fileDialog.ShowDialog() != CommonFileDialogResult.Ok) { return; } if (!DockControl?.IsVisible ?? true) { DockControl?.Show(); } MediaLoaded = true; Playing = true; //MediaPlayer.Play(new Media(_libVLC, fileDialog.FileName)); await VideoElement.Open(new Uri(fileDialog.FileName)); await VideoElement.Play(); }
private async void PageLoaded(object sender, RoutedEventArgs e) { VideoElement.MediaOpened += (s, args) => { Progress.Maximum = VideoElement.NaturalDuration.TimeSpan.TotalSeconds; DurationLabel.Text = VideoElement.NaturalDuration.TimeSpan.ToString(@"hh\:mm\:ss"); }; IRandomAccessStream source = null; do { source = await GetSource(); } while (source == null); VideoElement.SetSource(source, ""); Progress.Minimum = 0; Progress.IsThumbToolTipEnabled = false; _timer = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(0.2) }; _timer.Tick += UpdateVideoPosition; _timer.Start(); SystemNavigationManager.GetForCurrentView().BackRequested += NavigateBackRequested; SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = Frame.CanGoBack ? AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.Collapsed; }
/// <summary> /// Play next song in playlist. /// </summary> public async void BtnPlay_Click(object sender, RoutedEventArgs e) { _videoPlay = true; _forcePaused = false; if (ComponentPlayer.Current == null) { BtnOpen_Click(sender, e); return; } switch (ComponentPlayer.Current.PlayerStatus) { case PlayerStatus.Playing: if (VideoElement?.Source != null) { await VideoElement.Pause(); } PauseMedia(); break; case PlayerStatus.Ready: case PlayerStatus.Stopped: case PlayerStatus.Paused: if (VideoElement?.Source != null) { await VideoElement.Play(); } PlayMedia(); break; } }
//接受語音事件 private void SreSpeechRecognized(object sender, SpeechRecognizedEventArgs e) { /* * if (e.Result.Confidence < 0.2)//肯定度低於0.6,判為錯誤語句 * { * return; * }*/ switch (e.Result.Text.ToUpperInvariant()) { case "STOP": VideoElement.Pause(); break; case "PLAY": VideoElement.Play(); break; case "LOUD": VideoElement.Volume += 2; break; case "XIAO SHENG": VideoElement.Volume += -1; break; case "TIMEOUT": unit = 7; MessageBox.Show("暫停"); break; } }
private async void MediaPlayer_MediaOpenedAsync(FrameMediaPlayer sender, object args) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { VideoElement.SetMediaPlayer(mediaPlayer.MediaPlayer); }); }
public void a_foreach_and_multiple_current_items_in_custom_element_produces_the_correct_html_output() { var video = new VideoElement(); var values = new [] { "one", "two" }; video.OuterXml.ShouldBe("<div><ul><li><a href=\"one\">one</a></li><li><a href=\"two\">two</a></li></ul></div>"); }
protected override void OnNavigatedFrom(NavigationEventArgs e) { base.OnNavigatedFrom(e); VideoElement.Stop(); _timer.Stop(); _timer.Tick -= UpdateVideoPosition; SystemNavigationManager.GetForCurrentView().BackRequested -= NavigateBackRequested; }
private async Task PlayVideo() { if (VideoElement.MediaState == MediaPlaybackState.Play) { return; } await VideoElement.Play(); }
private async Task PauseVideo() { if (VideoElement.MediaState != MediaPlaybackState.Play) { return; } await VideoElement.Pause(); }
private async Task StopVideo() { if (VideoElement.MediaState != MediaPlaybackState.Play) { return; } await VideoElement.Stop(); }
private void SetupVideo() { VideoElement.Source = new Uri(Settings.Default.VideoSource); VideoElement.MediaEnded += (sender, args) => { VideoElement.Stop(); PlayButton.Visibility = Visibility.Visible; _mainWindows.Show(); }; }
private async void Command_UnloadMedia(object sender, ExecutedRoutedEventArgs e) { //MediaPlayer.Stop(); await VideoElement.Stop(); await VideoElement.Close(); MediaLoaded = false; Position.Time = 0; }
private void SeekToPosition(long time) { var target = TimeSpan.FromMilliseconds(time); if (target.TotalMilliseconds < 0) { target = TimeSpan.Zero; } VideoElement.Seek(target).GetAwaiter().GetResult(); Position.Time = (long)target.TotalMilliseconds; }
private void SetUpVideo() //get the incoming video object, load it into MediaElement for playback and pause it { VideoElement.Source = new Uri(VideoPath, UriKind.Absolute); VideoElement.MediaFailed += MediaFailed; VideoElement.Loaded += MediaLoaded; VideoElement.Pause(); GetVideoDuration(); //get videos duration TimeSpan time = TimeSpan.FromSeconds(0); //go to the beginning of of the video VideoElement.Position = time; }
public void JumpDuration(long duration) { var target = VideoElement.Position + TimeSpan.FromMilliseconds(duration); if (target.TotalMilliseconds < 0) { target = TimeSpan.Zero; } VideoElement.Seek(target).GetAwaiter().GetResult(); Position.Time = (long)target.TotalMilliseconds; }
private IEnumerable <VideoElement> UpdateFileOnTempDirectory(VideoElement video) { var content = FileProvider.ReadAllText(_filePath); var videos = JsonConvert.DeserializeObject <List <VideoElement> >(content) ?? new List <VideoElement>(); videos.Add(video); CreateFileOnTempDirectory(videos); return(videos); }
private void PlayStopButtonClick(object sender, RoutedEventArgs e) { if (PlayButton.IsChecked.Value) { VideoElement.Play(); PlayButton.Content = "\ue103"; } else { VideoElement.Pause(); PlayButton.Content = "\ue102"; } }
private async void VideoElement_MediaOpened(object sender, RoutedEventArgs e) { VideoElementBorder.Visibility = Visibility.Visible; if (!_videoPlay) { return; } await Task.Run(() => _waitAction?.Invoke()); await VideoElement.Play(); VideoElement.Position = _position; }
protected override void OnNavigatedTo(NavigationEventArgs e) { SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible; Uri sourceUri = (Uri)e.Parameter; if (sourceUri != null) { mediaPlayer = new MediaPlayer(); MediaSource source = MediaSource.CreateFromUri(sourceUri); mediaPlayer.Source = source; mediaPlayer.MediaOpened += MediaPlayer_MediaOpened; VideoElement.SetMediaPlayer(mediaPlayer); } }
private void ControllerViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { var property = typeof(TelloControllerViewModel).GetProperty(e.PropertyName); var value = property.GetValue(sender); Debug.WriteLine($"{nameof(ControllerViewModel_PropertyChanged)} - property '{e.PropertyName}', value '{value}'"); if (e.PropertyName == nameof(TelloControllerViewModel.IsVideoStreaming) && (bool)value) { VideoElement.Play(); } else { VideoElement.Stop(); } }
public PlaybackView() { InitializeComponent(); VideoElement.PositionChanged += (o, args) => Position.Time = (long)args.Position.TotalMilliseconds; VideoElement.MediaOpened += (o, args) => Position.Total = (long)args.Info.Duration.TotalMilliseconds; VideoElement.MediaFailed += (o, args) => Console.WriteLine(@"[FFME] MediaFailed : " + args.ErrorException); VideoElement.MediaEnded += async(o, args) => { await VideoElement.Seek(TimeSpan.Zero); await VideoElement.Play(); }; //VideoElement.RenderingVideo += RenderPreviewOnVideo; Position.OnPositionActiveChanged += () => SeekToPosition(Position.Time); }
public IEnumerable <VideoElement> UpdateJsonFileWithValue(VideoElement video) { if (FileProvider.Exists(_filePath)) { return(UpdateFileOnTempDirectory(video)); } else { var videos = new List <VideoElement> { video }; CreateFileOnTempDirectory(videos); return(videos); } }
//private async void VideoPlay() //{ // //await VideoElement.Pause(); // //await VideoElement.Play(); //} private async Task VideoJumpTo(int milliseconds) { _waitActionCts = new MyCancellationTokenSource(); Guid?guid = _waitActionCts?.Guid; var trueOffset = milliseconds + _videoOffset; if (trueOffset < 0) { await VideoElement.Pause(); VideoElement.Position = TimeSpan.FromMilliseconds(0); await Task.Run(() => { Thread.Sleep(TimeSpan.FromMilliseconds(-trueOffset)); }); if (_waitActionCts?.Guid != guid || _waitActionCts?.IsCancellationRequested == true) { return; } if (!_forcePaused) { await VideoElement.Play(); } else { await VideoElement.Pause(); } } else { //if (_mediaEnded) //{ // VideoElement.Position = TimeSpan.FromMilliseconds(0); // await Task.Run(() => { Thread.Sleep(10); }); //} if (!_forcePaused) { await VideoElement.Play(); } else { await VideoElement.Pause(); } VideoElement.Position = TimeSpan.FromMilliseconds(trueOffset); } }
//返回按鍵,關閉聲音撥放計算 private void back_Click(object sender, RoutedEventArgs e) { times = 0; second = 0; unit = 0; action = 0; res[0] = 0; res[1] = 0; finish = 0; VideoElement.Stop(); GoodElement.Stop(); LeftNegativeElement.Stop(); LeftPositiveElement.Stop(); RightNegativeElement.Stop(); RightPositiveElement.Stop(); BGMusicElement.Stop(); this.NavigationService.Navigate(menu); }
static void Main(string[] args) { var MediaStorage = new MediaStorage(new List <IPlayable>(), new List <IMediaList>()); var Directory = Environment.CurrentDirectory; //аудио Guid id = Guid.NewGuid(); IPlayable element = new AudioElement(id, "AudioElement", null, new System.IO.FileInfo(Directory + "\\Баста.mp3")); MediaStorage.AddPlayable(element); Player player = new Player(new PlayableAdapterFactory()); player.Play(MediaStorage.IPlayableFindById(id)); //видео id = Guid.NewGuid(); element = new VideoElement(id, "VideoElement", null, new System.IO.FileInfo(Directory + "\\Баста.mp4")); MediaStorage.AddPlayable(element); player.Play(MediaStorage.IPlayableFindById(id)); //список Guid idMediaList = Guid.NewGuid(); IMediaList UserList = new AudioUserList(idMediaList, "AudioUserList", (ICollection <IPlayable>)MediaStorage.IPlayablesFindByName("AudioElement")); MediaStorage.AddMediaList(UserList); id = Guid.NewGuid(); element = new AudioElement(id, "AudioElement2", null, new System.IO.FileInfo(Directory + "\\Баста.mp3")); MediaStorage.AddPlayableFromMediaList(UserList, element); IMediaList mls = MediaStorage.IMediaListFindById(idMediaList); player.Play(mls.Items); Console.ReadLine(); }
private async Task ClearVideoElement(bool seek) { await Task.Run(async() => { await VideoElement.Stop(); Dispatcher.Invoke(() => { VideoElement.Position = new TimeSpan(0); VideoElement.Source = null; VideoElement.Dispose(); VideoElement = null; VideoElementBorder.Visibility = Visibility.Hidden; VideoElement = new Unosquare.FFME.MediaElement { IsMuted = true, LoadedBehavior = MediaState.Manual, Visibility = System.Windows.Visibility.Visible, }; VideoElement.MediaOpened += VideoElement_MediaOpened; VideoElement.MediaFailed += VideoElement_MediaFailed; VideoElement.MediaEnded += (sender, e) => { VideoElement.Position = TimeSpan.FromSeconds(0); }; if (seek) { VideoElement.SeekingStarted += (sender, e) => { }; VideoElement.SeekingEnded += (sender, e) => { if (!_videoPlay) { return; } PlayMedia(); }; } VideoElementBorder.Children.Add(VideoElement); }); }); }
private async void Button_Click(object sender, RoutedEventArgs e) { AdaptiveMediaSourceCreationResult result = null; try { result = await AdaptiveMediaSource.CreateFromUriAsync(new Uri(UrlBox.Text)); VideoElement.SetMediaStreamSource(result.MediaSource); } catch { try { VideoElement.Source = new Uri(UrlBox.Text); } catch { await Message(); return; } } }
protected override void OnNavigatedFrom(NavigationEventArgs e) { if (mediaPlayer != null) { mediaPlayer.PlaybackSession.PlaybackStateChanged -= PlaybackSession_PlaybackStateChanged; mediaPlayer.MediaOpened -= MediaPlayer_MediaOpened; } if (mtcGrid != null) { mtcGrid.PointerPressed -= OnPointerPressed; mtcGrid.PointerReleased -= OnPointerReleased; mtcGrid.PointerWheelChanged -= OnPointerWheelChanged; VideoElement.PointerPressed -= OnPointerPressed; VideoElement.PointerReleased -= OnPointerReleased; VideoElement.PointerMoved -= OnPointerMoved; VideoElement.PointerWheelChanged -= OnPointerWheelChanged; Window.Current.CoreWindow.KeyDown -= OnKeyDown; } SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed; mediaPlayer.Source = null; VideoElement.SetMediaPlayer(null); mediaPlayer = null; }
private void InitializeVideo() { if (!_videoInitilized) { _videoInitilized = true; var videoEncodingProperties = VideoEncodingProperties.CreateH264(); videoEncodingProperties.Height = 720; videoEncodingProperties.Width = 960; var mediaStreamSource = new MediaStreamSource(new VideoStreamDescriptor(videoEncodingProperties)) { // never turn live on because it tries to skip frame which breaks the h264 decoding //IsLive = true, BufferTime = TimeSpan.FromSeconds(0.0) }; mediaStreamSource.SampleRequested += MediaStreamSource_SampleRequested; VideoElement.SetMediaStreamSource(mediaStreamSource); // never turn real time playback on //_mediaElement.RealTimePlayback = true; } }
public void TexSubImage2D(uint target, int level, int xoffset, int yoffset, uint format, uint type, VideoElement video) { }
public void a_foreach_and_multiple_current_items_in_custom_element_produces_the_correct_html_output() { var video = new VideoElement(); var values = new [] {"one", "two"}; video.OuterXml.ShouldBe("<div><ul><li><a href=\"one\">one</a></li><li><a href=\"two\">two</a></li></ul></div>"); }
public void TexImage2D(uint target, int level, uint internalformat, uint format, uint type, VideoElement video) { }