Click here to Skip to main content
14,207,985 members
Click here to Skip to main content
Add your own
alternative version

Stats

761.7K views
31.2K downloads
292 bookmarked
Posted 14 Sep 2010
Licenced CPOL

PVS.AVPlayer - Audio and Video Player Library

, 14 Jun 2019
Microsoft Media Foundation (MF) based easy-to-use 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 .NET 4.8
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 PVS.AVPlayer;
using System;
using System.Windows.Forms;

#endregion

namespace FolderView
{
    public partial class Form2 : Form
    {
        // A simple PlayerWindow.

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

        # region Fields

        Player      _myPlayer1;
        bool        _userMuted;
        public bool LastError;

        #endregion

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

        #region Main

        public Form2(string theMovie, TimeSpan position)
        {
            InitializeComponent();
            Icon = System.Drawing.SystemIcons.Application;

            positionLabel1.Font = Globals.CrystalFont16;
            positionLabel1.UseCompatibleTextRendering = true;
            positionLabel2.Font = Globals.CrystalFont16;
            positionLabel2.UseCompatibleTextRendering = true;

            Text = theMovie;

            _myPlayer1 = new Player()
            {
                Display = panel1,
                PositionSlider = customSlider21,
                Repeat = true,
            };

            _myPlayer1.MediaPositionChanged += myPlayer1_MediaPositionChanged;
            _myPlayer1.Play(theMovie);
            LastError = _myPlayer1.LastError;

            if (!LastError) _myPlayer1.Position = position;
        }

        // Enable audio when form activated
        private void Form2_Activated(object sender, EventArgs e)
        {
            if (!_userMuted) _myPlayer1.AudioEnabled = true;
        }

        // Mute audio when form deactivated
        private void Form2_Deactivate(object sender, EventArgs e)
        {
            _myPlayer1.AudioEnabled = false;
        }

        // Copied from Form2.Designer.cs to here
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                _myPlayer1.MediaPositionChanged -= myPlayer1_MediaPositionChanged;
                _myPlayer1.Dispose();
                if (components != null) components.Dispose();
            }
            base.Dispose(disposing);
        }

        #endregion

        // ******************************** Player Position Counters Eventhandler

        #region Player Position Counters Eventhandler

        // The playback position of a mediafile has changed - update position info labels
        void myPlayer1_MediaPositionChanged(object sender, EventArgs e)
        {
            TimeSpan[] t = _myPlayer1.GetTrackTimes();
            positionLabel1.Text = t[0].ToString().Substring(0, 8); // hh:mm:ss
            positionLabel2.Text = t[1].ToString().Substring(0, 8);
        }

        #endregion

        // ******************************** Contextmenu Handler

        #region Contextmenu Handler

        // Pause / Resume
        private void pauseMenuItem_Click(object sender, EventArgs e)
        {
            if (_myPlayer1.Paused)
            {
                _myPlayer1.Paused = _userMuted = false;
                pauseMenuItem.Text = "Pause";
            }
            else
            {
                _myPlayer1.Paused = _userMuted = true;
                pauseMenuItem.Text = "Resume";
            }
        }

        // Mute On / Off
        private void muteMenuItem_Click(object sender, EventArgs e)
        {
            if (_myPlayer1.AudioEnabled)
            {
                _myPlayer1.AudioEnabled = false;
                _userMuted = true;
                muteMenuItem.Text = "Mute Off";
            }
            else
            {
                _myPlayer1.AudioEnabled = true;
                _userMuted = false;
                muteMenuItem.Text = "Mute";
            }
        }

        // DisplayMode Stretch
        private void stretchMenuItem_Click(object sender, EventArgs e)
        {
            _myPlayer1.DisplayMode = DisplayMode.Stretch;
            stretchMenuItem.Checked = true;
            zoomAndCenterMenuItem.Checked = false;
        }

        // DisplayMode ZoomAndCenter
        private void zoomAndCenterMenuItem_Click(object sender, EventArgs e)
        {
            _myPlayer1.DisplayMode = DisplayMode.ZoomAndCenter;
            zoomAndCenterMenuItem.Checked = true;
            stretchMenuItem.Checked = false;
        }

        // FullScreen On / Off
        private void fullScreenMenuItem_Click(object sender, EventArgs e)
        {
            if (_myPlayer1.FullScreen)
            {
                _myPlayer1.FullScreen = false;
                fullScreenMenuItem.Text = "FullScreen";
            }
            else
            {
                _myPlayer1.FullScreen = true;
                fullScreenMenuItem.Text = "FullScreen Off";
            }
        }

        // Properties
        private void propertiesMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                SafeNativeMethods.SHELLEXECUTEINFO info = new SafeNativeMethods.SHELLEXECUTEINFO();
                info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info);
                info.lpVerb = "properties";
                info.lpFile = _myPlayer1.GetMediaName(MediaName.FullPath);
                info.nShow = SafeNativeMethods.SW_SHOW;
                info.fMask = SafeNativeMethods.SEE_MASK_INVOKEIDLIST;
                SafeNativeMethods.ShellExecuteEx(ref info);
            }
            catch { }
        }

        // Close
        private void closeMenuItem_Click(object sender, EventArgs e)
        {
            Dispose(true);
        }

        #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

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.190612.1 | Last Updated 14 Jun 2019
Article Copyright 2010 by Peter Vegter
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid