Click here to Skip to main content
13,703,265 members
Click here to Skip to main content

Stats

694.5K views
29.6K downloads
281 bookmarked
Posted 14 Sep 2010
Licenced CPOL

PVS.AVPlayer - MCI Audio and Video Library

, 7 Aug 2018
Windows Media Control Interface (MCI) library with many added features
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 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 2.png
Dial Green 4.png
Dial Green.png
Dial Red 2.png
Dial Red.png
media7.ico
media7a.ico
Media8.ico
Media8a.ico
VU Meter.png
WingDings3a.ttf
Sound Recorder
Various
About Dialog
PVS.AVPlayer.dll
PVS.AVPlayer.XML
Custom Items
FolderView.csproj.user
Debug
Bob.png
Crystal Italic1.ttf
media7a.ico
media7b.ico
Media8a.ico
Media8b.ico
Subtitles Overlay
Various
How To (C#)
PVSAVPlayerHowTo
bin
Debug
PVS.AVPlayer.dll
PVS.AVPlayer.XML
Release
obj
Debug
Release
Properties
How To (VB.NET)
PVSAVPlayerHowToVB
bin
Debug
PVS.AVPlayer.dll
PVS.AVPlayer.XML
Release
My Project
Application.myapp
obj
Debug
Release
PVSAVPlayerHowTo.vbproj.user
PVS.AVPlayer Examples
AVPlayerExample.ex_
FolderView.ex_
AVPlayerExample.exe
FolderView.exe
PVS.AVPlayer.dll
#region Usings

using PVS.AVPlayer;
using System;
using System.Windows.Forms;

#endregion

namespace AVPlayerExample
{
    public partial class StatusInfoOverlay : Form, IOverlay
    {
        /*
        
        PVS.AVPlayer Display Overlay - Example 'StatusInfo'
        Shows some information about the player and the playing media.

        As with all example overlays this is just a simple implementation that can easily
        be expanded (and/or improved) to fit your needs.
        
        */

        // ******************************** Fields

        #region Fields

        private Form1           _baseForm;
        private readonly Player _basePlayer;
        private OverlayMode     _baseOverlayMode;

        #endregion

        // ******************************** Initialize & Form event handling

        #region Initialize & Form and Player event handling

        // Main
        public StatusInfoOverlay(Form1 baseForm, Player basePlayer)
        {
            InitializeComponent();

            _baseForm = baseForm;
            _basePlayer = basePlayer;
            versionLabel.Text = Player.VersionString + " (" + (IntPtr.Size == 8 ? "64": "32") + "-bit)";

            // Pass on drag and drop to main form (handled in source file: DragDrop.cs):
            AllowDrop = true;
            DragEnter += _baseForm.Form1_DragEnter;
            DragDrop += _baseForm.Form1_DragDrop;
        }

        // Called when the form is shown or hidden
        private void StatusInfoOverlay_VisibleChanged(object sender, EventArgs e)
        {
            if (Visible)
            {
                _baseOverlayMode = _basePlayer.OverlayMode;
                _basePlayer.OverlayMode = OverlayMode.Display;
                SetPlayerEventHandlers();
                SetAllInfo();
            }
            else
            {
                RemovePlayerEventHandlers();
                _basePlayer.OverlayMode = _baseOverlayMode;
            }
        }

        private void SetPlayerEventHandlers()
        {
            // Handle "All"
            _basePlayer.MediaStarted += SetAllInfoEventHandler;

            // Handle "Status"
            _basePlayer.MediaPaused += SetStatusInfoEventHandler;
            _basePlayer.MediaResumed += SetStatusInfoEventHandler;

            // Handle "Media"
            _basePlayer.MediaStartEndMediaChanged += SetMediaInfoEventHandler;
            _basePlayer.MediaRepeatChanged += SetMediaInfoEventHandler;
            _basePlayer.MediaSpeedChanged += SetMediaInfoEventHandler;

            // Handle "Video"
            _basePlayer.MediaVideoEnabledChanged += SetVideoInfoEventHandler;
            _basePlayer.MediaVideoBoundsChanged += SetVideoInfoEventHandler;
            SizeChanged += SetVideoDisplayInfoEventHandler; // also handles "Display" (Size)

            // Handle "Audio"
            _basePlayer.MediaAudioEnabledChanged += SetAudioInfoEventHandler;
            _basePlayer.MediaAudioVolumeChanged += SetAudioInfoEventHandler;
            _basePlayer.MediaAudioBalanceChanged += SetAudioInfoEventHandler;

            // Handle "Display"
            _basePlayer.MediaDisplayChanged += SetVideoDisplayInfoEventHandler;
            _basePlayer.MediaDisplayModeChanged += SetVideoDisplayInfoEventHandler;
            _basePlayer.MediaFullScreenChanged += SetVideoDisplayInfoEventHandler;
            _basePlayer.MediaFullScreenModeChanged += SetVideoDisplayInfoEventHandler;
        }

        private void RemovePlayerEventHandlers()
        {
            _basePlayer.MediaStarted -= SetAllInfoEventHandler;

            _basePlayer.MediaPaused -= SetStatusInfoEventHandler;
            _basePlayer.MediaResumed -= SetStatusInfoEventHandler;

            _basePlayer.MediaStartEndMediaChanged -= SetMediaInfoEventHandler;
            _basePlayer.MediaRepeatChanged -= SetMediaInfoEventHandler;
            _basePlayer.MediaSpeedChanged -= SetMediaInfoEventHandler;

            _basePlayer.MediaVideoEnabledChanged -= SetVideoInfoEventHandler;
            _basePlayer.MediaVideoBoundsChanged -= SetVideoInfoEventHandler;
            SizeChanged -= SetVideoDisplayInfoEventHandler; // also handles "Display" (Size)

            _basePlayer.MediaAudioEnabledChanged -= SetAudioInfoEventHandler;
            _basePlayer.MediaAudioVolumeChanged -= SetAudioInfoEventHandler;
            _basePlayer.MediaAudioBalanceChanged -= SetAudioInfoEventHandler;

            _basePlayer.MediaDisplayChanged -= SetVideoDisplayInfoEventHandler;
            _basePlayer.MediaDisplayModeChanged -= SetVideoDisplayInfoEventHandler;
            _basePlayer.MediaFullScreenChanged -= SetVideoDisplayInfoEventHandler;
            _basePlayer.MediaFullScreenModeChanged -= SetVideoDisplayInfoEventHandler;
        }

        // The EventHandlers:

        void SetAllInfoEventHandler(object sender, EventArgs e)
        {
            SetAllInfo();
        }

        void SetStatusInfoEventHandler(object sender, EventArgs e)
        {
            SetStatusInfo();
        }

        void SetMediaInfoEventHandler(object sender, EventArgs e)
        {
            SetMediaInfo();
        }

        void SetVideoInfoEventHandler(object sender, EventArgs e)
        {
            SetVideoInfo();
        }

        void SetAudioInfoEventHandler(object sender, EventArgs e)
        {
            SetAudioInfo();
        }

        void SetVideoDisplayInfoEventHandler(object sender, EventArgs e)
        {
            SetVideoInfo(); // for videosize
            SetDisplayInfo();
        }

        #endregion

        // ******************************** IOverlay Control

        #region IOverlay Control

        // The visibility of the menu is controlled by the user from the main application (in this example application)
        public bool HasMenu
        {
            get { return false; }
        }

        public bool MenuEnabled
        {
            get { return false; }
            set { }
        }

        public void MediaStopped()
        {
            if (Visible) SetAllInfo();
        }

        #endregion

        // ******************************** Set the Info

        #region Set the Info

        private void SetAllInfo()
        {
            SuspendLayout();
            SetStatusInfo();
            SetMediaInfo();
            SetVideoInfo();
            SetAudioInfo();
            SetDisplayInfo();
            ResumeLayout();
        }

        private void SetStatusInfo()
        {
            if (_basePlayer.Playing)
            {
                statusLabel.Text = _basePlayer.Paused ? "Paused" : "Playing";
                deviceLabel.Text = _basePlayer.MciDeviceType + " (" + _basePlayer.MciDeviceName + ")";
            }
            else
            {
                statusLabel.Text = "No Media";
                deviceLabel.Text = "-";
            }
        }

        private void SetMediaInfo()
        {
            if (_basePlayer.Playing)
            {
                mediaLabel.Text = _basePlayer.GetMediaName(MediaName.FileName);
                durationLabel.Text = _basePlayer.GetMediaLength(MediaLength.Total).ToString().Substring(0, 8);

                startLabel.Text = _basePlayer.StartPositionMedia.TotalSeconds == 0 ? "Begin of Media" : _basePlayer.StartPositionMedia.ToString().Substring(0, 8);
                endLabel.Text = _basePlayer.EndPositionMedia.TotalSeconds == 0 ? "End of Media" : _basePlayer.EndPositionMedia.ToString().Substring(0, 8);

                repeatLabel.Text = _basePlayer.Repeat ? "Yes" : "No";
                speedLabel.Text = _basePlayer.Speed + " (" + (_basePlayer.Speed / 10).ToString("0") + "%)";
            }
            else
            {
                mediaLabel.Text = "-";
                durationLabel.Text = "-";
                startLabel.Text = "-";
                endLabel.Text = "-";
                repeatLabel.Text = "-";
                speedLabel.Text = "-";
            }
        }

        private void SetVideoInfo()
        {
            if (_basePlayer.VideoPresent)
            {
                videoLabel.Text = "Present";
                videoEnabledLabel.Text = _basePlayer.VideoEnabled ? "Yes" : "No";
                originalSizeLabel.Text = _basePlayer.VideoSourceSize.ToString().TrimStart('{').TrimEnd('}');
                currentSizeLabel.Text = _basePlayer.VideoBounds.ToString().TrimStart('{').TrimEnd('}');
                frameRateLabel.Text = (_basePlayer.FrameRate/1000) + " frames per second";
            }
            else
            {
                videoLabel.Text = _basePlayer.Playing ? "Not Present" : "-";
                videoEnabledLabel.Text = "-";
                originalSizeLabel.Text = "-";
                currentSizeLabel.Text = "-";
                frameRateLabel.Text = "-";
            }
        }

        private void SetAudioInfo()
        {
            if (_basePlayer.AudioPresent)
            {
                audioLabel.Text = "Present";
                audioEnabledLabel.Text = _basePlayer.AudioEnabled ? "Yes" : "No";

                //volumeLabel.Text = basePlayer.AudioVolume.ToString() + " (" + (basePlayer.AudioVolume / 10).ToString("0") + "%)";
                volumeLabel.Text = _basePlayer.AudioVolume.ToString();
                switch (_basePlayer.AudioVolume)
                {
                    case 1000:
                        volumeLabel.Text += " (Maximum)";
                        break;
                    case 0:
                        volumeLabel.Text += " (Mute)";
                        break;
                    default:
                        volumeLabel.Text += " (" + (_basePlayer.AudioVolume / 10).ToString("0") + "%)";
                        break;
                }

                balanceLabel.Text = _basePlayer.AudioBalance.ToString();
                if (_basePlayer.AudioBalance == 500) balanceLabel.Text += " (Center)";
                else
                {
                    if (_basePlayer.AudioBalance < 500) balanceLabel.Text += " (Left " + ((500 - _basePlayer.AudioBalance) / 5).ToString("0") + "%)";
                    else balanceLabel.Text += " (Right " + ((_basePlayer.AudioBalance - 500) / 5).ToString("0") + "%)";
                }
            }
            else
            {
                audioLabel.Text = _basePlayer.Playing ? "Not Present" : "-";
                audioEnabledLabel.Text = "-";
                volumeLabel.Text = "-";
                balanceLabel.Text = "-";
            }
        }

        private void SetDisplayInfo()
        {
            if (_basePlayer.Display != null)
            {
                displayLabel.Text = _basePlayer.Display.Name + " (" + _basePlayer.Display.GetType() + ")";
                displaySizeLabel.Text = _basePlayer.Display.Size.ToString().TrimStart('{').TrimEnd('}');
                displayModeLabel.Text = _basePlayer.DisplayMode.ToString();
                fullScreenLabel.Text = _basePlayer.FullScreen ? "FullScreen " + _basePlayer.FullScreenMode : "Window";
            }
            else
            {
                displayLabel.Text = "None";
                displaySizeLabel.Text = "-";
                displayModeLabel.Text = "-";
                fullScreenLabel.Text = "-";
            }
        }

        #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
Web01-2016 | 2.8.180920.1 | Last Updated 7 Aug 2018
Article Copyright 2010 by Peter Vegter
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid