示例#1
0
        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();
            }
        }
示例#2
0
        private void MvPlayer_SubtitleChanged(object sender, MV_SubtitleEventArgs e)
        {
            ClearSubtitleLines();

            if (e.Lines == null || e.Lines.Count == 0)
            {
                return;
            }

            //not elegant solution to set subtitle lines
            //but its only example
            //in true environment it should be more flexible collection management with visual items

            int idx = e.Lines.Count - 1;

            if (e.Lines.Count > 0)
            {
                subLine1.Text = e.Lines[idx].Line;

                if (e.Lines[idx].isBold)
                {
                    subLine1.FontWeight = FontWeights.Bold;
                }

                if (e.Lines[idx].isItalic)
                {
                    subLine1.FontStyle = FontStyles.Italic;
                }

                idx--;
            }

            if (e.Lines.Count > 1)
            {
                subLine2.Text = e.Lines[idx].Line;

                if (e.Lines[idx].isBold)
                {
                    subLine2.FontWeight = FontWeights.Bold;
                }

                if (e.Lines[idx].isItalic)
                {
                    subLine2.FontStyle = FontStyles.Italic;
                }

                idx--;
            }

            if (e.Lines.Count > 2)
            {
                subLine3.Text = e.Lines[idx].Line;

                if (e.Lines[idx].isBold)
                {
                    subLine3.FontWeight = FontWeights.Bold;
                }

                if (e.Lines[idx].isItalic)
                {
                    subLine3.FontStyle = FontStyles.Italic;
                }

                idx--;
            }

            if (e.Lines.Count > 3)
            {
                subLine4.Text = e.Lines[idx].Line;

                if (e.Lines[idx].isBold)
                {
                    subLine4.FontWeight = FontWeights.Bold;
                }

                if (e.Lines[idx].isItalic)
                {
                    subLine4.FontStyle = FontStyles.Italic;
                }
            }
        }