Click here to Skip to main content
13,598,868 members
Click here to Skip to main content

Stats

657.2K views
29K downloads
273 bookmarked
Posted 14 Sep 2010
Licenced CPOL

PVS.AVPlayer - MCI Audio and Video Library

, 1 Jun 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
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
Properties
How To (VB.NET)
PVSAVPlayerHowToVB
bin
Debug
PVS.AVPlayer.dll
PVS.AVPlayer.XML
Release
My Project
Application.myapp
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.Drawing;
using System.Drawing.Text;
using System.Windows.Forms;

#endregion

namespace AVPlayerExample
{
    public sealed partial class BigTimeOverlay : Form, IOverlay
    {
        /*

        PVS.AVPlayer Display Overlay - Example 'Big Time'
        Displays large timecounters using embedded digital font
        and -optional- audio peaklevel meters.

        */

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

        #region Fields

        private bool        _isActive;
        private MainWindow   _baseWindow;
        private Player      _basePlayer;
        private Font        _crystalFont45;
        private bool        _smallDisplay;
        private bool        _busy;
        private bool        _progressTime = true;

        // VU Meters
        private bool        _vuMetersEnabled;
        private bool        _vuMetersHidden;
        private VU_Meter    _leftVUMeter;
        private VU_Meter    _rightVUMeter;

        private bool        _disposed;

        #endregion

        // ******************************** Main

        #region Main

        public BigTimeOverlay(MainWindow baseWindow, Player basePlayer, PrivateFontCollection fontCollection)
        {
            InitializeComponent();

            _baseWindow = baseWindow;
            _basePlayer = basePlayer;
            _crystalFont45 = new Font(fontCollection.Families[0], 45, FontStyle.Italic);

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

            startTimerLabel.Font = _crystalFont45;
            startTimerLabel.UseCompatibleTextRendering = true;
            endTimerLabel.Font = _crystalFont45;
            endTimerLabel.UseCompatibleTextRendering = true;
        }

        protected override bool ShowWithoutActivation
        {
            get { return true; }
        }

        private void BigTimeOverlay_VisibleChanged(object sender, EventArgs e)
        {
            if (Visible)
            {
                BigTimeOverlay_SizeChanged(this, EventArgs.Empty); // set initial position
                SizeChanged += BigTimeOverlay_SizeChanged;
                _basePlayer.Events.MediaPositionChanged += BasePlayer_MediaPositionChanged;
                // get values if paused:
                if (_basePlayer.Playing && _basePlayer.Paused) SetTimeValues();
                // Vu meters
                if (_vuMetersHidden) ShowVUMeters();
                _isActive = true;
            }
            else
            {
                SizeChanged -= BigTimeOverlay_SizeChanged;
                _basePlayer.Events.MediaPositionChanged -= BasePlayer_MediaPositionChanged;
                // Vu meters
                HideVUMeters(true);
                _isActive = false;
            }
        }

        private void BigTimeOverlay_SizeChanged(object sender, EventArgs e)
        {
            if (Width < 650)
            {
                if (!_smallDisplay)
                {
                    startTimerLabel.Top = Height - 120;
                    endTimerLabel.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
                    endTimerLabel.Left = startTimerLabel.Left;
                    _smallDisplay = true;

                    if (_vuMetersEnabled) HideVUMeters(true);
                }
            }
            else if (_smallDisplay)
            {
                startTimerLabel.Top = Height - 60;
                endTimerLabel.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
                endTimerLabel.Left = Width - 320;
                _smallDisplay = false;

                if (_vuMetersHidden) ShowVUMeters();
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    if (_leftVUMeter != null)
                    {
                        if (_vuMetersEnabled) _basePlayer.Events.MediaPeakLevelChanged -= BasePlayer_MediaPeakLevelChanged;
                        _leftVUMeter.Dispose();
                        _rightVUMeter.Dispose();
                    }

                    if (_isActive)
                    {
                        SizeChanged -= BigTimeOverlay_SizeChanged;
                        _basePlayer.Events.MediaPositionChanged -= BasePlayer_MediaPositionChanged;
                    }

                    _crystalFont45.Dispose(); _crystalFont45 = null;
                    _basePlayer = null;

                    DragDrop -= _baseWindow.Form1_DragDrop;

                    if (components != null) components.Dispose();
                }
                _disposed = true;
            }
            base.Dispose(disposing);
        }

        #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 MenuEnabled
        {
            get { return optionsPanel.Visible; }
            set { optionsPanel.Visible = value; }
        }

        public bool HasMenu
        {
            get { return true; }
        }

        public void MediaStopped()
        {
            startTimerLabel.Text = endTimerLabel.Text = "00:00:00.000";
        }

        #endregion

        // ******************************** Options Menu

        #region Options Menu

        #region Time

        private void TrackTimeMenuItem_Click(object sender, EventArgs e)
        {
            _progressTime = false;
            startTimerLabel.Invalidate();
            endTimerLabel.Invalidate();

            trackTimeMenuItem.Checked = true;
            progressTimeMenuItem.Checked = false;
        }

        private void ProgressTimeMenuItem_Click(object sender, EventArgs e)
        {
            _progressTime = true;
            startTimerLabel.Invalidate();
            endTimerLabel.Invalidate();

            trackTimeMenuItem.Checked = false;
            progressTimeMenuItem.Checked = true;
        }

        private void ColorMenuItem_Click(object sender, EventArgs e)
        {
            ColorDialog colorDialog = new ColorDialog { Color = startTimerLabel.ForeColor };
            if (colorDialog.ShowDialog(this) == DialogResult.OK)
            {
                startTimerLabel.ForeColor = endTimerLabel.ForeColor = colorDialog.Color;

                int r = startTimerLabel.ForeColor.R > 253 ? startTimerLabel.ForeColor.R - 2 : startTimerLabel.ForeColor.R + 2;
                int g = startTimerLabel.ForeColor.G > 253 ? startTimerLabel.ForeColor.G - 2 : startTimerLabel.ForeColor.G + 2;
                int b = startTimerLabel.ForeColor.B > 253 ? startTimerLabel.ForeColor.B - 2 : startTimerLabel.ForeColor.B + 2;
                BackColor = Color.FromArgb(r, g, b);
                TransparencyKey = BackColor;
            }
            colorDialog.Dispose();
        }

        #endregion

        #region VU Meters

        private void ShowVUMetersMenuItem_Click(object sender, EventArgs e)
        {
            if (_vuMetersEnabled || _vuMetersHidden)
            {
                HideVUMeters(false);
            }
            else
            {
                if (_leftVUMeter == null)
                {
                    Point p = new Point(10, this.Height - 216);
                    _leftVUMeter = new VU_Meter();
                    _leftVUMeter.Location = p;
                    _leftVUMeter.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
                    _leftVUMeter.Visible = false;
                    this.Controls.Add(_leftVUMeter);
                    _leftVUMeter.SendToBack();

                    _rightVUMeter = new VU_Meter();
                    p.X = this.Width - _rightVUMeter.Width - 10;
                    _rightVUMeter.Location = p;
                    _rightVUMeter.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
                    _rightVUMeter.Visible = false;
                    this.Controls.Add(_rightVUMeter);
                    _leftVUMeter.SendToBack();
                }
                ShowVUMeters();
            }
        }

        private void ShowVUMeters()
        {
            if (!_vuMetersEnabled)
            {
                if (_smallDisplay)
                {
                    _vuMetersHidden = true;
                }
                else
                {
                    _basePlayer.Events.MediaPeakLevelChanged += BasePlayer_MediaPeakLevelChanged;
                    _vuMetersEnabled = _leftVUMeter.Visible = _rightVUMeter.Visible = true;
                    _vuMetersHidden = false;
                }
                showVUMetersMenuItem.Text = "Hide VU Meters";
            }
        }

        private void HideVUMeters(bool forced)
        {
            if (_vuMetersEnabled)
            {
                _vuMetersEnabled = _leftVUMeter.Visible = _rightVUMeter.Visible = false;
                _basePlayer.Events.MediaPeakLevelChanged -= BasePlayer_MediaPeakLevelChanged;
                _leftVUMeter.Value = _rightVUMeter.Value = -1;
                if (!forced) showVUMetersMenuItem.Text = "Show VU Meters";
                _vuMetersHidden = forced;
            }
            else if (_vuMetersHidden && !forced)
            {
                _vuMetersHidden = false;
                showVUMetersMenuItem.Text = "Show VU Meters";
            }
        }

        #endregion

        #region Opacity

        // Opacity 25%
        private void Opacity25_MenuItem_Click(object sender, EventArgs e)
        {
            Opacity = 0.25;
            SetOpacityMenu(sender);
        }

        // Opacity 50%
        private void Opacity50_MenuItem_Click(object sender, EventArgs e)
        {
            Opacity = 0.50;
            SetOpacityMenu(sender);
        }

        // Opacity 75%
        private void Opacity75_MenuItem_Click(object sender, EventArgs e)
        {
            Opacity = 0.75;
            SetOpacityMenu(sender);
        }

        // Opacity 100%
        private void Opacity100_MenuItem_Click(object sender, EventArgs e)
        {
            Opacity = 1;
            SetOpacityMenu(sender);
        }

        // Checks the selected Opacity menu item and removes the check marks from the others
        private void SetOpacityMenu(object sender)
        {
            foreach (ToolStripItem item in (((ToolStripMenuItem)sender).GetCurrentParent().Items))
            {
                if (item.GetType() == typeof(ToolStripMenuItem))
                {
                    ((ToolStripMenuItem)item).Checked = item == sender;
                }
            }

            opacityMenuItem.Checked = (Opacity != 1);
        }

        #endregion

        #endregion

        // ******************************** Player PositionChanged / PeakLevelChanged Eventhandlers

        #region Player PositionChanged / SetPositionValues / PeakLevelChanged Eventhandlers

        private void BasePlayer_MediaPositionChanged(object sender, PositionEventArgs e)
        {
            if (_busy) return;
            _busy = true;

            TimeSpan t0, t1;

            if (_progressTime)
            {
                t0 = e.FromStart;
                t1 = e.ToStop;
            }
            else
            {
                t0 = e.FromBegin;
                t1 = e.ToEnd;
            }

            startTimerLabel.Text = string.Format("{0:00;00}:{1:00;00}:{2:00;00}.{3:000;000}", t0.Hours, t0.Minutes, t0.Seconds, t0.Milliseconds);
            endTimerLabel.Text = string.Format("{0:00;00}:{1:00;00}:{2:00;00}.{3:000;000}", t1.Hours, t1.Minutes, t1.Seconds, t1.Milliseconds);

            _busy = false;
        }

        private void SetTimeValues()
        {
            TimeSpan t0, t1;
            if (_progressTime)
            {
                t0 = _basePlayer.Position.FromStart;
                t1 = _basePlayer.Position.ToStop;
            }
            else
            {
                t0 = _basePlayer.Position.FromBegin;
                t1 = _basePlayer.Position.ToEnd;
            }

            startTimerLabel.Text = string.Format("{0:00;00}:{1:00;00}:{2:00;00}.{3:000;000}", t0.Hours, t0.Minutes, t0.Seconds, t0.Milliseconds);
            endTimerLabel.Text = string.Format("{0:00;00}:{1:00;00}:{2:00;00}.{3:000;000}", t1.Hours, t1.Minutes, t1.Seconds, t1.Milliseconds);
        }

        private void BasePlayer_MediaPeakLevelChanged(object sender, PeakLevelEventArgs e)
        {
            _leftVUMeter.Value = e.LeftLevel;
            _rightVUMeter.Value = e.RightLevel;
        }

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