Click here to Skip to main content
13,705,563 members
Click here to Skip to main content

Stats

695.8K 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.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Xml.Serialization;

#endregion

namespace FolderView
{
    public partial class Form1 : Form
    {
        // PVS.AVPlayer Example - FolderView 0.46
        // A simple movie folder viewer.

        // Peter Vegter
        // August 2015, The Netherlands

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

        #region Fields

        // To avoid too much CPU-usage and/or memory usage
        private const int       MAX_VIEW_PLAYERS                = 40;   // The maximum number of players in a folderview
        private const int       MAX_PLAYING_BACKGROUND_PLAYERS  = 12;   // If more than this: pause all folderview players when opening detailview
        private const int       START_POSITION_PERCENT          = 10;

        // Movie file extensions to look for (this list starts with .lnk (shortcut file))
        private const string    MOVIE_EXTENSIONS = ".lnk.asf.avi.bik.divx.dvx.f4v.flv.h264.hdmov.mkv.mod.mov.mp4.mpeg.mpeg4.mpg.mpv.mts.ogv.qt.rm.rms.swf.vfw.vob.wmv.xvid";

        // Players and Displays (ItemViews)
        private int             _activeCount;
        private int             _playerCount;
        private Player[]        _myPlayers;
        private ItemView[]      _myItemViews;

        // ItemViews Label Colors
        private readonly Color  NORMAL_COLOR        = Color.FromArgb(189, 159, 87);
        private readonly Color  ERROR_COLOR         = Color.Firebrick;
        private readonly Color  AUDIO_ENABLED_COLOR = Color.ForestGreen;

        // Folder Selector
        private FolderBrowserDialog _folderBrowserDialog1;
        private List<string>        _fileList;

        // FolderView
        private bool            _busy;
        private bool            _hasQueue;
        private string          _queuePath;
        private bool            _exit;

        // Contextmenu Handler
        private int             _playerId;

        // Preferences
        [Serializable]
        public struct           Preferences
        {
            public Rectangle    WindowBounds;
            public bool         WindowMaximized;
            public string       InitialDirectory;
        }
        private Preferences     _prefs;
        private const string    PREFS_FILENAME    = "FolderView.inf";
        private readonly string PREFS_PATH        = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\FolderView\";

        // Dispose
        private bool            _disposed;

        #endregion

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

        #region Main

        // Initialize
        public Form1()
        {
            InitializeComponent();
            Icon = SystemIcons.Application;

            // Set custom menus
            ToolStripManager.Renderer = new CustomMenuRenderer();

            // Set custom font
            InstallFontCollection();
            countLabel1.Font = Globals.CrystalFont26;
            countLabel1.UseCompatibleTextRendering = true;
            countLabel2.Font = Globals.CrystalFont26;
            countLabel2.UseCompatibleTextRendering = true;

            // FlowLayoutPanel scroll and click eventhandlers
            flowLayoutPanel1.Scroll += flowLayoutPanel1_Scroll;
            flowLayoutPanel1.MouseWheel += flowLayoutPanel1_MouseWheel;
            flowLayoutPanel1.Click += flowLayoutPanel1_Click;

            // Create a FolderBrowserDialog
            _folderBrowserDialog1 = new FolderBrowserDialog
            {
                Description = Text + "\n\r\n\rPlease select a movies folder:",
                ShowNewFolderButton = false
            };

            // Adjust submenus margins
            ((ToolStripDropDownMenu)allMenuItem.DropDown).ShowImageMargin = false;
            ((ToolStripDropDownMenu)displayModeAllMenuItem.DropDown).ShowImageMargin = false;

            // Load settings
            GetSettings();

            // Create a filelist (to store moviefilenames in a directory)
            _fileList = new List<string>(MAX_VIEW_PLAYERS);

            // Add text maximum number of files to tooltips
            toolTip1.SetToolTip(countLabel1, toolTip1.GetToolTip(countLabel1) + MAX_VIEW_PLAYERS.ToString() + ").");
            toolTip1.SetToolTip(countLabel2, toolTip1.GetToolTip(countLabel2) + MAX_VIEW_PLAYERS.ToString() + ").");

            // finishing setup in Form1_Shown... (for 'smoother' form display)

        }

        private void Form1_Shown(object sender, EventArgs e)
        {
            // Set initial FolderView
            CreateFolderView(_folderBrowserDialog1.SelectedPath);
        }

        private void Form1_Activated(object sender, EventArgs e)
        {
            flowLayoutPanel1.Focus();
        }

        // Handle mouseclick on 'empty space' in window
        void flowLayoutPanel1_Click(object sender, EventArgs e)
        {
            if (_folderBrowserDialog1.ShowDialog(this) == DialogResult.OK)
            {
                CreateFolderView(_folderBrowserDialog1.SelectedPath);
            }
        }

        // Repairing scroll redraw issues with paused players
        private void flowLayoutPanel1_Scroll(object sender, ScrollEventArgs e)
        {
            flowLayoutPanel1.Invalidate(true);
        }
        // ... and with
        void flowLayoutPanel1_MouseWheel(object sender, MouseEventArgs e)
        {
            flowLayoutPanel1.Invalidate(true);
        }

        // Don't close the Form (application) yet when a Player starts playing a mediafile (in method CreateFolderView)
        // (because a Player allows user interface actions while 'processing' a mediafile and
        // all Displays and Players will be 'disposed' when closing the Form)
        // 'sends a message' to CreateFolderView (if busy)
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (_busy)
            {
                _exit = true; // do Application.Exit() when finished
                _hasQueue = true; // don't create new ItemViews, Players or start playing a mediafile
                e.Cancel = true; // don't exit app (yet)
            }
            else
            {
                Hide();
                // Save settings
                SaveSettings();
                // Dispose all open Forms but this one
                for (int i = Application.OpenForms.Count - 1; i >= 0; i--)
                {
                    if (Application.OpenForms[i] != this) Application.OpenForms[i].Dispose();
                }
            }
        }

        // Moved from Form1.Designer.cs to here and added a few things
        protected override void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    RemoveFolderView();
                    _folderBrowserDialog1.Dispose();
                    _fileList.Clear();

                    Globals.CrystalFont16.Dispose();
                    Globals.CrystalFont26.Dispose();
                    Globals.FontCollection1.Dispose();

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

        #endregion

        // ******************************** Settings - Config File

        #region Settings - Config File

        private void GetSettings()
        {
            bool loadOk = false;

            // Load and Apply Settings
            if (File.Exists(PREFS_PATH + PREFS_FILENAME))
            {
                try
                {
                    using (StreamReader reader = new StreamReader(PREFS_PATH + PREFS_FILENAME))
                    {
                        XmlSerializer xml = new XmlSerializer(typeof(Preferences));
                        _prefs = (Preferences) xml.Deserialize(reader);
                    }
                    loadOk = true;
                }
                catch { /* ignore */ }
            }

            if (loadOk)
            {
                StartPosition = FormStartPosition.Manual;
                Bounds = _prefs.WindowBounds;
                if (_prefs.WindowMaximized) WindowState = FormWindowState.Maximized;
                _folderBrowserDialog1.SelectedPath = _prefs.InitialDirectory;
            }
            else
            {
                _folderBrowserDialog1.SelectedPath = Environment.GetFolderPath(_folderBrowserDialog1.RootFolder);
            }
        }

        private void SaveSettings()
        {
            // Collect Settings
            _prefs.WindowBounds       = WindowState == FormWindowState.Normal ? Bounds : RestoreBounds;
            _prefs.WindowMaximized    = WindowState == FormWindowState.Maximized;
            _prefs.InitialDirectory   = _folderBrowserDialog1.SelectedPath;

            // Save Settings
            try
            {
                Directory.CreateDirectory(PREFS_PATH); // create folder if not already existing
                using (StreamWriter writer = new StreamWriter(PREFS_PATH + PREFS_FILENAME))
                {
                    XmlSerializer xml = new XmlSerializer(typeof(Preferences));
                    xml.Serialize(writer, _prefs);
                }
            }
            catch { /* ignore */ }
        }

        #endregion

        // ******************************** Create / Remove FolderView / ResolveShortcut

        #region Create / Remove FolderView / ResolveShortcut

        // Create and display a new Folder view
        private void CreateFolderView(string path)
        {
            if (_busy)
            {
                _hasQueue = true;
                _queuePath = path;
                return;
            }
            _busy = true;

            do 
            {
                RemoveFolderView();
                _fileList.Clear();

                if (_hasQueue)
                {
                    _hasQueue = false;
                    folderLabel.Text = _queuePath;
                }
                else folderLabel.Text = path;

                try
                {
                    // Get all mediafiles in folder
                    foreach (string file in Directory.GetFiles(folderLabel.Text))
                    {
                        int index = MOVIE_EXTENSIONS.IndexOf(Path.GetExtension(file), StringComparison.OrdinalIgnoreCase);
                        if (index == 0) // .lnk - shortcut file
                        {
                            string linkFile = ResolveShortcut(file);
                            if (MOVIE_EXTENSIONS.IndexOf(Path.GetExtension(linkFile), StringComparison.OrdinalIgnoreCase) > 0)
                            {
                                _fileList.Add(linkFile);
                            }
                        }
                        else if (index > 0)
                        {
                            _fileList.Add(file);
                        }
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                    continue;
                }

                if (_fileList.Count > 0)
                {
                    // Set (max) number of Players
                    _playerCount = _fileList.Count > MAX_VIEW_PLAYERS ? MAX_VIEW_PLAYERS : _fileList.Count;

                    // Create Displays and Players
                    _myItemViews = new ItemView[_playerCount];
                    _myPlayers = new Player[_playerCount];

                    for (int i = 0; i < _playerCount && !_hasQueue; i++)
                    {
                        _myItemViews[i] = new ItemView()
                        {
                            Name = i.ToString(),
                            ContextMenuStrip = contextMenuStrip1,
                        };
                        _myItemViews[i].Display.Click += Display_Click; // panel
                        _myItemViews[i].FileName.Click += FileName_Click; // label
                        _myItemViews[i].FileName.ForeColor = NORMAL_COLOR;
                        _myItemViews[i].FileName.Text = Path.GetFileName(_fileList[i]);

                        _myPlayers[i] = new Player()
                        {
                            Display = _myItemViews[i].Display,
                            PositionSlider = _myItemViews[i].customSlider1,
                            AudioEnabled = false,
                            Repeat = true
                        };

                        if (_playerCount > MAX_PLAYING_BACKGROUND_PLAYERS) _myPlayers[i].Paused = true;
                    }

                    // Add items to TableLayoutPanel
                    if (!_hasQueue)
                    {
                        flowLayoutPanel1.Controls.AddRange(_myItemViews);
                        countLabel1.Text = _playerCount.ToString("000");
                    }

                    // Start Players
                    for (int i = 0; i < _playerCount && !_hasQueue; i++)
                    {
                        _myPlayers[i].Play(_fileList[i]);
                        if (_myPlayers[i].LastError)
                        {
                            _myPlayers[i].Dispose();
                            _myPlayers[i] = null;
                            _myItemViews[i].customSlider1.Enabled = false;
                            _myItemViews[i].FileName.ForeColor = ERROR_COLOR;
                        }
                        else
                        {
                            countLabel2.Text = (++_activeCount).ToString("000");
                            // set playback position to START_POSITION_PERCENT of total lenght
                            _myPlayers[i].Position = TimeSpan.FromMilliseconds((_myPlayers[i].GetMediaLength(MediaLength.Total).TotalMilliseconds / (100 / START_POSITION_PERCENT)));
                        }
                    }

                    // See Form1_FormClosing eventhandler
                    if (_exit)
                    {
                        _hasQueue = false;
                        _busy = false;
                        Application.Exit();
                    }
                }
            }  while (_hasQueue);

            _busy = false;
        }

        private void RemoveFolderView()
        {
            // reset counters
            _activeCount = 0;
            countLabel1.Text = "000";
            countLabel2.Text = "000";

            if (_playerCount > 0)
            {
                flowLayoutPanel1.Controls.Clear();

                // Dispose Players and remove and dispose ItemViews
                for (int i = 0; i < _playerCount; i++)
                {
                    if (_myPlayers[i] != null)
                    {
                        _myPlayers[i].Dispose();
                        _myPlayers[i] = null;
                    }

                    if (_myItemViews[i] != null)
                    {
                        _myItemViews[i].ContextMenuStrip = null;
                        _myItemViews[i].Dispose();
                        _myItemViews[i] = null;
                    }
                }

                _playerCount = 0;
            }
        }

        // taken from: https://blez.wordpress.com/2013/02/18/get-file-shortcuts-target-with-c/
        private string ResolveShortcut(string fileName)
        {
            //if (!String.Equals(Path.GetExtension(fileName), ".lnk", StringComparison.OrdinalIgnoreCase)) return string.Empty;
            try
            {
                FileStream fileStream = File.Open(fileName, FileMode.Open, FileAccess.Read);
                using (BinaryReader fileReader = new BinaryReader(fileStream))
                {
                    fileStream.Seek(0x14, SeekOrigin.Begin);     // Seek to flags
                    uint flags = fileReader.ReadUInt32();        // Read flags
                    if ((flags & 1) == 1)
                    {   
                        // Bit 1 set means we have to skip the shell item ID list
                        fileStream.Seek(0x4c, SeekOrigin.Begin); // Seek to the end of the header
                        uint offset = fileReader.ReadUInt16();   // Read the length of the Shell item ID list
                        fileStream.Seek(offset, SeekOrigin.Current); // Seek past it (to the file locator info)
                    }

                    long fileInfoStartsAt = fileStream.Position; // Store the offset where the file info
                    // structure begins
                    uint totalStructLength = fileReader.ReadUInt32(); // read the length of the whole struct
                    fileStream.Seek(0xc, SeekOrigin.Current); // seek to offset to base pathname
                    uint fileOffset = fileReader.ReadUInt32(); // read offset to base pathname
                    // the offset is from the beginning of the file info struct (fileInfoStartsAt)
                    fileStream.Seek((fileInfoStartsAt + fileOffset), SeekOrigin.Begin); // Seek to beginning of
                    // base pathname (target)
                    long pathLength = (totalStructLength + fileInfoStartsAt) - fileStream.Position - 2; // read
                    // the base pathname. I don't need the 2 terminating nulls.
                    char[] linkTarget = fileReader.ReadChars((int)pathLength); // should be unicode safe
                    string link = new string(linkTarget);

                    int begin = link.IndexOf("\0\0", StringComparison.Ordinal);
                    if (begin > -1)
                    {
                        int end = link.IndexOf("\\\\", begin + 2, StringComparison.Ordinal) + 2;
                        end = link.IndexOf('\0', end) + 1;

                        string firstPart = link.Substring(0, begin);
                        string secondPart = link.Substring(end);

                        return firstPart + secondPart;
                    }
                    return link;
                }
            }
            catch
            {
                return string.Empty;
            }
        }

        #endregion

        // ******************************** ItemView Click Eventhandlers

        #region ItemView Click Eventhandlers

        // Handle ItemView Panel Click
        void Display_Click(object sender, EventArgs e)
        {
            _playerId = Convert.ToInt32(((Panel)sender).Parent.Name);
            openMenuItem_Click(sender, e);
        }

        // Handle ItemView Label Click
        void FileName_Click(object sender, EventArgs e)
        {
            _playerId = Convert.ToInt32(((Label)sender).Parent.Name);
            openMenuItem_Click(sender, e);
        }

        #endregion

        // ******************************** Contextmenu Handlers

        #region Contextmenu Items Handlers

        // ******************************** ContextMenu Opening and Closing

        // Before contextmenu is shown or closed:
        private void contextMenuStrip1_Opening(object sender, System.ComponentModel.CancelEventArgs e)
        {
            _playerId = Convert.ToInt32(((ContextMenuStrip)sender).SourceControl.Name);
            bool enable = _myPlayers[_playerId] != null;

            pauseMenuItem.Enabled = enable;
            muteMenuItem.Enabled = enable;
            displayModeMenuItem.Enabled = enable;

            if (enable)
            {
                pauseMenuItem.Text = _myPlayers[_playerId].Paused ? "Play" : "Pause";
                muteMenuItem.Text = _myPlayers[_playerId].AudioEnabled ? "Mute" : "Mute Off";

                stretchMenuItem.Checked = _myPlayers[_playerId].DisplayMode == DisplayMode.Stretch;
                zoomAndCenterMenuItem.Checked = !stretchMenuItem.Checked;
            }
            else
            {
                pauseMenuItem.Text = "Play";
                muteMenuItem.Text = "Mute Off";
            }

            ((ItemView)contextMenuStrip1.SourceControl).FileName.BackColor = Color.FromArgb(64, 24, 24);

        }

        private void contextMenuStrip1_Closing(object sender, ToolStripDropDownClosingEventArgs e)
        {
            ((ItemView)contextMenuStrip1.SourceControl).FileName.BackColor = BackColor; // Color.FromArgb(18, 18, 18);
        }

        // ******************************** Change Folder

        // Change Folder
        private void changeFolderMenuItem_Click(object sender, EventArgs e)
        {
            if (_folderBrowserDialog1.ShowDialog(this) == DialogResult.OK)
            {
                CreateFolderView(_folderBrowserDialog1.SelectedPath);
            }
        }

        // ******************************** All Items

        // Play (Resume) all Players
        private void playAllMenuItem_Click(object sender, EventArgs e)
        {
            PauseAllPlayers(false);
        }

        // Pause all Players
        private void pauseAllMenuItem_Click(object sender, EventArgs e)
        {
            PauseAllPlayers(true);
        }

        // Mute all Players
        private void muteAllMenuItem_Click(object sender, EventArgs e)
        {
            AudioMuteAllPlayers();
        }

        // DisplayMode Stretch all Players
        private void stretchAllMenuItem_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < _myPlayers.Length; i++)
            {
                if (_myPlayers[i] != null) _myPlayers[i].DisplayMode = DisplayMode.Stretch;
            }
        }

        // DisplayMode ZoomAndCenter all Players
        private void zoomAndCenterAllMenuItem_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < _myPlayers.Length; i++)
            {
                if (_myPlayers[i] != null) _myPlayers[i].DisplayMode = DisplayMode.ZoomAndCenter;
            }
        }

        // ******************************** Selected Player

        // Play (Resume) / Pause selected Player
        private void pauseMenuItem_Click(object sender, EventArgs e)
        {
            _myPlayers[_playerId].Paused = !_myPlayers[_playerId].Paused;
        }

        // Mute On / Off selected Player
        private void muteMenuItem_Click(object sender, EventArgs e)
        {
            if (_myPlayers[_playerId].AudioEnabled)
            {
                _myPlayers[_playerId].AudioEnabled = false;
                _myItemViews[_playerId].FileName.ForeColor = NORMAL_COLOR;
            }
            else
            {
                AudioMuteAllPlayers();
                _myPlayers[_playerId].AudioEnabled = true;
                _myItemViews[_playerId].FileName.ForeColor = AUDIO_ENABLED_COLOR;
            }
        }

        // DisplayMode Stretch selected Player
        private void stretchMenuItem_Click(object sender, EventArgs e)
        {
            _myPlayers[_playerId].DisplayMode = DisplayMode.Stretch;
        }

        // DisplayMode ZoomAndCenter selected Player
        private void zoomAndCenterMenuItem_Click(object sender, EventArgs e)
        {
            _myPlayers[_playerId].DisplayMode = DisplayMode.ZoomAndCenter;
        }

        // ******************************** Open, Open With..., Properties

        // Open mediafile in new window or in other application
        private void openMenuItem_Click(object sender, EventArgs e)
        {
            if (_myPlayers.Length > MAX_PLAYING_BACKGROUND_PLAYERS) PauseAllPlayers(true);
            AudioMuteAllPlayers();

            if (_myPlayers[_playerId] != null)
            {
                Form2 playerForm = new Form2(_fileList[_playerId], _myPlayers[_playerId].Position);
                if (playerForm.LastError)
                {
                    playerForm.Dispose();
                }
                else
                {
                    playerForm.Show();
                    // playerForm handles itself, just let go:
                    // not closing them when folderview changes
                    return;
                }
            }

            try { System.Diagnostics.Process.Start(_fileList[_playerId]); }
            catch { }
        }

        // Select application to open mediafile
        private void openWithMenuItem_Click(object sender, EventArgs e)
        {
            if (_myPlayers.Length > MAX_PLAYING_BACKGROUND_PLAYERS) PauseAllPlayers(true);
            AudioMuteAllPlayers();

            try { System.Diagnostics.Process.Start("rundll32.exe", "shell32.dll,OpenAs_RunDLL " + _fileList[_playerId]); }
            catch { }
        }

        // Show mediafile Explorer properties dialog
        private void propertiesMenuItem_Click(object sender, EventArgs e)
        {
            // 'dirty trick' to position properties dialog - should have a second look at this
            Cursor.Position = PointToScreen(new Point(_myItemViews[_playerId].Left + (_myItemViews[_playerId].Width / 2), _myItemViews[_playerId].Top + (_myItemViews[_playerId].Height / 3)));
            
            try
            {
                SafeNativeMethods.SHELLEXECUTEINFO info = new SafeNativeMethods.SHELLEXECUTEINFO();
                info.cbSize = Marshal.SizeOf(info);
                info.lpVerb = "properties";
                info.lpFile = _fileList[_playerId];
                info.nShow = SafeNativeMethods.SW_SHOW;
                info.fMask = SafeNativeMethods.SEE_MASK_INVOKEIDLIST;
                SafeNativeMethods.ShellExecuteEx(ref info);
            }
            catch { }
        }

        // ******************************** Quit

        // Quit application
        private void quitMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        }

        // ******************************** Contextmenu Helper methods

        // Pause / Resume playback all Players
        private void PauseAllPlayers(bool pause)
        {
            for (int i = 0; i < _myPlayers.Length; i++)
            {
                if (_myPlayers[i] != null) _myPlayers[i].Paused = pause;
            }
        }

        private void AudioMuteAllPlayers()
        {
            for (int i = 0; i < _myPlayers.Length; i++)
            {
                if (_myPlayers[i] != null && _myPlayers[i].AudioEnabled)
                {
                    _myPlayers[i].AudioEnabled = false;
                    _myItemViews[i].FileName.ForeColor = NORMAL_COLOR;
                }
            }
        }

        #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