private void eventsDispatcher_Tick(object sender, EventArgs e) { List <EventItem> items = new List <EventItem>(); lock (_events_lock) { while (_events.Count > 0) { items.Add(_events.Dequeue()); } } //dispatch events foreach (EventItem i in items) { //media changed if (i.eventType == 0) { MV_MediaStateChangedEventArgs args = (MV_MediaStateChangedEventArgs)i.eventData; if (MediaStateChanged != null) { MediaStateChanged(this, args); } continue; } //fps update if (i.eventType == 1) { Form parent = this.TopLevelControl as Form; if (parent != null) { parent.Text = string.Format("{0:F2} FPS ", i.eventData); parent = null; } continue; } //position changed if (i.eventType == 2) { MV_MediaPositionChangedEventArgs args = (MV_MediaPositionChangedEventArgs)i.eventData; if (MediaPositionChanged != null) { MediaPositionChanged(this, args); } continue; } } items.Clear(); }
private void MvPlayer1_MediaStateChanged(object sender, MV_MediaStateChangedEventArgs e) { //check if we are in MVAuto mode //if so, we can use fallback if hw decoding will fail if (mvPlayer1.MediaState == MV_PlayerStateEnum.Error && mvPlayer1.DecodingType == MV_DecodingTypeEnum.MV_Auto) { //close failed source mvPlayer1.Close(); //change decoding type into sw yuv decoding //mvPlayer1.DecodingType = MV_DecodingTypeEnum.MV_YUV420P; cmbDecodingType.SelectedIndex = (int)MV_DecodingTypeEnum.MV_YUV420P; mvPlayer1.OpenMediaAsync(currentFileName); } lblPlayerState.Text = mvPlayer1.MediaState.ToString(); if (e.State != MV_PlayerStateEnum.Error && e.State != MV_PlayerStateEnum.NotInitialized && e.State != MV_PlayerStateEnum.Closed && e.State != MV_PlayerStateEnum.Loading) { tbPosition.Enabled = true; //prepare slider if media are ready if (setupSlider) { setupSlider = false; TimeSpan position_t = TimeSpan.FromSeconds(mvPlayer1.MediaPosition); TimeSpan duration_t = TimeSpan.FromSeconds(mvPlayer1.MediaDuration); tbPosition.Value = 0; tbPosition.Maximum = (int)Math.Floor(mvPlayer1.MediaDuration); lblPositionData.Text = string.Format("{0:00}:{1:00}:{2:00} / {3:00}:{4:00}:{5:00}", position_t.Hours, position_t.Minutes, position_t.Seconds, duration_t.Hours, duration_t.Minutes, duration_t.Seconds); lblMediaSizeData.Text = string.Format("Width: {0} Height: {1}", mvPlayer1.VideoWidth, mvPlayer1.VideoHeight); } } else { tbPosition.Enabled = false; } if (e.State == MV_PlayerStateEnum.Seeking) { lastSeekOperation = DateTime.Now; } }
private void CompositionTarget_Rendering(object sender, EventArgs e) { if (ShowFPS) { _frameCount++; if (_clock != null && _clock.ElapsedMilliseconds >= 1000) { Window wnd_parent = Window.GetWindow(this); if (wnd_parent != null) { wnd_parent.Title = string.Format("FPS: {0}", _frameCount); } _frameCount = 0; _clock.Restart(); } } // Dirty hack to force WPF to refresh at vsync interval // let pretend we always have something to redraw // so funny tbh, who made that engine?????!!!??? this.Background = new SolidColorBrush(Color.FromRgb(0x0, 0x0, 0x0)); if (_media_wrapper == null) { return; } //event handling if (MediaPosition != _media_wrapper.GetPosition() && Math.Abs(_last_position_measure - MediaPosition) > PositionChangedStep) { _last_position_measure = _media_wrapper.GetPosition(); MV_MediaPositionChangedEventArgs args = new MV_MediaPositionChangedEventArgs(); args.Position = _media_wrapper.GetPosition(); if (MediaPositionChanged != null) { MediaPositionChanged(this, args); } } //update some media dependency properties if (_media_wrapper.GetPosition() != MediaPosition) { this.SetValue(MediaPositionProperty, _media_wrapper.GetPosition()); } if (_media_wrapper.GetDuration() != MediaDuration) { MediaDuration = _media_wrapper.GetDuration(); } if ((int)MediaState != _media_wrapper.GetPlayerState()) { MediaState = (MV_PlayerStateEnum)_media_wrapper.GetPlayerState(); MV_MediaStateChangedEventArgs args = new MV_MediaStateChangedEventArgs(); args.State = MediaState; if (MediaStateChanged != null) { MediaStateChanged(this, args); } } if (VideoWidth == 0 || VideoHeight == 0) { return; } if (HasOpenSubtitles) { bool IsNew = false; bool IsEmpty = false; List <string> textLines = new List <string>(); List <bool> textBoolFmt = new List <bool>(); List <bool> textItalicFmt = new List <bool>(); _media_wrapper.GetSubtitles(ref IsNew, ref IsEmpty, textLines, textBoolFmt, textItalicFmt); if (SubtitleChanged != null && (IsNew || (IsEmpty && _lastSubtitleNotEmpty))) { MV_SubtitleEventArgs args = new MV_SubtitleEventArgs(); _lastSubtitleNotEmpty = !IsEmpty; args.IsEmpty = IsEmpty; args.IsNew = IsNew; MV_SubtitleLines lines = new MV_SubtitleLines(); for (int a = 0; a < textLines.Count; a++) { MV_SubtitleLine line = new MV_SubtitleLine(); line.isBold = textBoolFmt[a]; line.isItalic = textItalicFmt[a]; line.Line = textLines[a]; lines.Add(line); } args.Lines = lines; SubtitleChanged(this, args); } } bool hasVideoFrame = _media_wrapper.RenderOffScreen(); if (hasVideoFrame && _d3d_surface == IntPtr.Zero) { _d3d_surface = _media_wrapper.GetOffScreenSurface(); if (_d3d_surface != IntPtr.Zero) { _d3d_render.Lock(); _d3d_render.SetBackBuffer(D3DResourceType.IDirect3DSurface9, _d3d_surface); _d3d_render.Unlock(); //restore window focus if (DecodingType == MV_DecodingTypeEnum.MV_RGBA || DecodingType == MV_DecodingTypeEnum.MV_YUV420P) { Window wnd = Window.GetWindow(this); if (wnd != null) { wnd.Activate(); } } } } if (_d3d_render.IsFrontBufferAvailable && hasVideoFrame && _d3d_surface != IntPtr.Zero) { // lock the D3DImage _d3d_render.Lock(); // invalidate the updated region of the D3DImage (in this case, the whole image) _d3d_render.AddDirtyRect(new Int32Rect(0, 0, VideoWidth, VideoHeight)); // unlock the D3DImage _d3d_render.Unlock(); } }
private void Render() { long fps = 0; bool show_fps = false; if (IsDisposed || _media_wrapper == null) { return; } lock (_render_locker) { bool rendered_frame = (bool)_media_wrapper.RenderScene((int)SizeMode, _force_render); _force_render = false; if (_render_mode == MV_RenderMode.Immediate) { System.Threading.Thread.Sleep(1); } if (ShowFPS && rendered_frame) { _frameCount++; if (_clock != null && _clock.ElapsedMilliseconds >= 1000) { fps = _frameCount; show_fps = true; _frameCount = 0; _clock.Restart(); } } } if (MediaState != _lastState) { MV_MediaStateChangedEventArgs args = new MV_MediaStateChangedEventArgs(); args.State = MediaState; EventItem item = new EventItem(); item.eventData = args; item.eventType = 0; //media state changed lock (_events_lock) { _events.Enqueue(item); } _lastState = args.State; } if (show_fps) { EventItem item = new EventItem(); item.eventData = fps; item.eventType = 1; //fps counter lock (_events_lock) { _events.Enqueue(item); } } if (Math.Abs(MediaPosition - _last_position_value) > PositionChangedStep) { double position = MediaPosition; MV_MediaPositionChangedEventArgs args = new MV_MediaPositionChangedEventArgs(); args.Position = position; EventItem item = new EventItem(); item.eventData = args; item.eventType = 2; //media position changed lock (_events_lock) { _events.Enqueue(item); } _last_position_value = position; } }