Click here to Skip to main content
14,177,047 members
Click here to Skip to main content

Stats

756.4K views
30.9K downloads
291 bookmarked
Posted 14 Sep 2010
Licenced CPOL

PVS.AVPlayer - Audio and Video Player Library

, 21 May 2019
Microsoft Media Foundation (MF) based easy-to-use library with many added features
Code Project PVS 0.95 Article
Image PVS-95-1.png
Image PVS-95-2.png
Image PVS-95-3.png
Image PVS-95-4.png
Image PVS-95-5.png
Image PVS-95-6.png
Image PVS-95-7.gif
PVS.AVPlayer
PVS.AVPlayer .NET 2.0
PVS.AVPlayer.XML
PVS.AVPlayer .NET 3.0
PVS.AVPlayer.XML
PVS.AVPlayer .NET 3.5
PVS.AVPlayer.XML
PVS.AVPlayer .NET 4.0
PVS.AVPlayer.XML
PVS.AVPlayer .NET 4.5
PVS.AVPlayer .NET 4.5.1
PVS.AVPlayer.XML
PVS.AVPlayer .NET 4.5.2
PVS.AVPlayer.XML
PVS.AVPlayer.XML
PVS.AVPlayer .NET 4.6
PVS.AVPlayer.XML
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer .NET 4.6.1
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer .NET 4.6.2
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer .NET 4.7
PVS.AVPlayer .NET 4.7.1
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer .NET 4.7.2
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer Licenses
PVS.AVPlayer All Source Code
AVPlayerExample
AVPlayerExample
AVPlayerExample.csproj.user
bin
Debug
PVS.AVPlayer.XML
Release
Dialogs
Display Overlays
obj
Debug
Release
x86
Debug
Release
Properties
Resources
Crystal Italic1.ttf
WingDings3a.ttf
Voice Recorder
FolderView
FolderView
bin
Debug
PVS.AVPlayer.XML
Release
FolderView.csproj.user
obj
Release
x86
Debug
Release
Properties
Resources
Crystal Italic1.ttf
PVS.AVPlayer
AVPlayerExample.csproj.user
PVS.AVPlayer.dll
PVS.AVPlayer.XML
Custom Items
Native Methods
Bob.png
Crystal Italic1.ttf
Dial Green.png
Dial Normal 2.png
Dial Red 2.png
Dial Red.png
Kaizen-4.png
Media Normal.ico
Media Paused.ico
Media Paused1.ico
Media Playing.ico
PVSLogo.png
PVSLogoOutline.png
VU Meter.png
WingDings3a.ttf
Various
PVS.AVPlayer Licenses
About Dialog
PVS.AVPlayer.dll
PVS.AVPlayer.XML
Custom Items
FolderView.csproj.user
Media8b.ico
Debug
Bob.png
Crystal Italic1.ttf
Media Paused.ico
media7a.ico
media7b.ico
Media8a.ico
Media8b.ico
PVSLogoOutline.png
Subtitles Overlay
Various
PVS.AVPlayer Licenses
How To (C#)
PVS.AVPlayer Licenses
PVSAVPlayerHowTo
bin
Debug
PVS.AVPlayer.dll
PVS.AVPlayer.XML
Release
obj
Debug
Release
Properties
How To (VB.NET)
PVS.AVPlayer Licenses
PVSAVPlayerHowToVB
bin
Debug
PVS.AVPlayer.dll
PVS.AVPlayer.XML
Release
My Project
Application.myapp
obj
Debug
Release
PVSAVPlayerHowTo.vbproj.user
PVS.AVPlayer Licenses
PVS.AVPlayer Examples
AVPlayerExample.ex_
FolderView.ex_
AVPlayerExample.exe
FolderView.exe
PVS.AVPlayer Licenses
PVS.AVPlayer.dll
#region Usings

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Security.Permissions;
using System.Windows.Forms;

#endregion

namespace AVPlayerExample
{
    public partial class MainWindow
    {
        // Automatically hide (after not having moved for a few seconds) and unhide (when moved/clicked) the mouse cursor when playing media.
        // A MessageFilter is used to detect mouse events.

        // For use with AVPlayerExample - for (general) use with other apps this code has to be changed/extended a little bit
        // - can also be easily changed to work with player displays instead of full forms

        #region Mouse Hide Fields

        private Timer           _mouseHideTimer;
        private DateTime        _mouseHideMoved;
        private Point           _mouseHideOldPosition;
        private bool            _mouseHideActive;
        private int             _mouseHideActiveCount;
        private bool            _mouseHideDisabled;
        private int             _mouseHideDisabledCount;
        private bool            _mouseHideHidden;
        private MouseHideFilter _mouseHideFilter;
        private List<Form>      _registeredForms;

        #endregion

        // *********

        #region Register Forms - Subscribe and unsubscribe Forms

        internal void RegisterMouseHideForm(Form form)
        {
            if (_registeredForms == null) _registeredForms = new List<Form>(8);
            if (!_registeredForms.Contains(form)) _registeredForms.Add(form);
        }

        internal void UnregisterMouseHideForm(Form form)
        {
            if (_registeredForms != null) _registeredForms.Remove(form);
        }

        #endregion

        // *********

        #region Mouse Hide activating and de-activating

        // It's assumed that there's at least 1 registered form - TODO suspend start if no registered forms
        internal void MouseHideStart()
        {
            if (Prefs.AutoHideCursor && !_mouseHideActive)
            {
                if (_mouseHideTimer == null)
                {
                    _mouseHideMoved = new DateTime();

                    _mouseHideTimer = new Timer();
                    _mouseHideTimer.Interval = Prefs.AutoHideCursorSeconds * 1000;
                    _mouseHideTimer.Tick += MouseHideTimer_Tick;

                    _mouseHideFilter = new MouseHideFilter();
                    _mouseHideFilter.Client = this;
                }

                _mouseHideMoved = DateTime.Now;
                _mouseHideTimer.Start();
                Application.AddMessageFilter(_mouseHideFilter);

                _mouseHideActiveCount++;
                _mouseHideActive = true;
            }
        }

        internal void MouseHideStop(bool dispose)
        {
            if ((--_mouseHideActiveCount <= 0 || dispose) && _mouseHideActive)
            {
                _mouseHideTimer.Stop();
                Application.RemoveMessageFilter(_mouseHideFilter);
                _mouseHideActive = false;

                if (_mouseHideHidden)
                {
                    Cursor.Show();
                    _mouseHideHidden = false;
                }
                _mouseHideActiveCount = 0;
            }

            //dispose = true is called from Dispose() (when quiting application) of MainWindow
            if (dispose && _mouseHideTimer != null)
            {
                _mouseHideTimer.Dispose();
                _mouseHideTimer = null;
                _mouseHideFilter.Client = null;
                _mouseHideFilter = null;
                _registeredForms.Clear();
                _registeredForms = null;
            }
        }

        #endregion

        #region Mouse Hide timer (hide) and mouse move and action (show) eventhandlers

        // strange: bottom scrolling text of message overlay influences ActiveForm value or mouse event?
        private void MouseHideTimer_Tick(object sender, EventArgs e)
        {
            if (_mouseHideDisabled) return;

            if (!_mouseHideHidden && Form.ActiveForm != null)
            {
                if ((DateTime.Now - _mouseHideMoved).TotalSeconds >= Prefs.AutoHideCursorSeconds)
                {
                    if (_registeredForms.Contains(Form.ActiveForm))
                    {
                        _mouseHideTimer.Stop();
                        _mouseHideOldPosition = Cursor.Position;
                        Cursor.Hide();
                        HideSliderPreviewByTimer();
                        _mouseHideHidden = true;
                    }
                }
            }
        }

        private void MouseHideMove()
        {
            _mouseHideMoved = DateTime.Now;
            if (_mouseHideHidden)
            {
                Point _mouseHideNewPosition = Cursor.Position;
                if (Math.Abs(_mouseHideNewPosition.X - _mouseHideOldPosition.X) >= 2 || Math.Abs(_mouseHideNewPosition.Y - _mouseHideOldPosition.Y) >= 2)
                {
                    Cursor.Show();
                    _mouseHideHidden = false;
                    _mouseHideTimer.Start();
                }
                else _mouseHideOldPosition = _mouseHideNewPosition;
            }
        }

        private void MouseHideAction()
        {
            _mouseHideMoved = DateTime.Now;
            if (_mouseHideHidden)
            {
                Cursor.Show();
                _mouseHideHidden = false;
                _mouseHideTimer.Start();
            }
        }

        #endregion

        // *********

        #region Temporarily disable MouseHide by contextmenus

        // Temporarily disable hiding of the mouse cursor (should be done for all pop-up menus)
        private void ContextMenu_Opening(object sender, CancelEventArgs e)
        {
            _mouseHideDisabled = true;
            _mouseHideDisabledCount++;
        }

        private void ContextMenu_Closing(object sender, ToolStripDropDownClosingEventArgs e)
        {
            if (--_mouseHideDisabledCount <= 0)
            {
                _mouseHideDisabled = false;
                _mouseHideDisabledCount = 0;
            }
        }

        #endregion

        // *********

        #region Mouse Hide MessageFilter

        public class MouseHideFilter : IMessageFilter
        {
            internal MainWindow Client;

            [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
            public bool PreFilterMessage(ref Message m)
            {
                if (m.Msg == 0x0200) Client.MouseHideMove(); // WM_MOUSEMOVE
                else if (m.Msg > 0x0200 && m.Msg <= 0x020A) Client.MouseHideAction();
                return false;
            }
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Peter Vegter
United States United States
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06 | 2.8.190526.1 | Last Updated 21 May 2019
Article Copyright 2010 by Peter Vegter
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid