Click here to Skip to main content
14,026,166 members
Click here to Skip to main content

Stats

747.4K views
30.2K 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.Drawing;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Windows.Forms;

#endregion

namespace AVPlayerExample
{
    public partial class Form1
    {
        // ******************************** Preferences

        #region Fields

        [Serializable]
        public class Preferences
        {
            public int Version;

            // Window
            public bool SaveWindow;
            public bool Maximized;
            public Rectangle Bounds;
            public bool Fullscreen;
            public FullScreenMode FullScreenMode;

            // DisplayMode
            public bool SaveDisplayMode;
            public DisplayMode DisplayMode;
            public Rectangle VideoBounds;

            // Overlay
            public bool AutoOverlay;
            public bool SaveOverlay;
            public int Overlay;

            // Position Slider
            public bool SaveSlider;
            public bool SliderVisible;
            public bool SliderProgress;
            public bool SliderLiveUpdate;

            // Repeat
            public bool SaveRepeat;
            public int Repeat; // 0 = off, 1 = one, 2 = all, 3 = shuffle

            // Speed
            public bool SaveSpeed;
            public int Speed;

            // Audio
            public bool SaveAudio;
            public int AudioVolume;
            public int AudioBalance;

            // Folders
            public bool SaveMediaFilesFolder;
            public string MediaFilesFolder;
            public bool SavePlaylistsFolder;
            public string PlaylistsFolder;

            // Continue Playing Media
            public bool ContinuePlay;
            public int MediaToPlay;
            public double Position;
            public double StartPosition;
            public double EndPosition;
            public bool Paused;
            public int RewindSecs;
            public bool VideoPresent;

            // PlayList
            public bool PlayListShowExtensions;
            public bool PlayListChanged;
            public string PlayListTitle;

            // Various
            public bool AutoPlayStart;
            public bool AutoPlayAdded;
            public bool AutoPlayNext;
            public bool OnErrorPlayNext;
            public bool OnErrorRemove;
            public bool ShowErrorMessages;

            // Tooltips & Dialog MiniPlayers
            public bool ShowTooltips;
            public bool ShowMiniPlayers;
        }

        private const int PLAYLIST_VERSION = 2;

        private string _prefsFile = _appDataPath + PREFERENCES_NAME + ".inf"; // preferences file path
        internal static Preferences Prefs;

        #endregion

        private void LoadPreferences()
        {
            bool loadOk = false;
            if (Prefs == null) Prefs = new Preferences();

            if (File.Exists(_prefsFile))
            {
                //Use this for loading an xml-type file:
                //try
                //{
                //    using (StreamReader reader = new StreamReader(_prefsFile))
                //    {
                //        XmlSerializer xml = new XmlSerializer(typeof(Preferences));
                //        Prefs = (Preferences)xml.Deserialize(reader);
                //    }
                //    loadOk = true;
                //}
                //catch { /* ignore */ }

                // Use this for loading a binary-type file:
                try
                {
                    using (FileStream stream = File.Open(_prefsFile, FileMode.Open))
                    {
                        BinaryFormatter bin = new BinaryFormatter();
                        Prefs = (Preferences)bin.Deserialize(stream);
                    }
                    loadOk = true;
                }
                catch { /* ignore */ }
            }

            if (loadOk)
            {
                SetPreferences();
            }
            else SetDefaultPreferences();
        }

        private void SavePreferences()
        {
            GetPreferences(); // collect settings

            // Use this for saving an xml-type file:
            //try
            //{
            //    using (StreamWriter writer = new StreamWriter(_prefsFile))
            //    {
            //        XmlSerializer xml = new XmlSerializer(typeof(Preferences));
            //        xml.Serialize(writer, Prefs);
            //    }
            //}
            //catch { /* ignore */ }

            // Use this for saving a binary-type file:
            try
            {
                using (FileStream stream = File.Open(_prefsFile, FileMode.Create))
                {
                    BinaryFormatter bin = new BinaryFormatter();
                    bin.Serialize(stream, Prefs);
                }
            }
            catch { /* ignore */ }
        }


        private void SetPreferences()
        {
            // Window
            if (Prefs.SaveWindow || (Prefs.ContinuePlay && Prefs.MediaToPlay >= 0))
            {
                // check if bounds are on (fully) any current screen (if saved with multiple screens setup)
                Rectangle r = Prefs.Bounds;
                r.Inflate(-16, -16); // add a little (off-screen) margin
                for (int i = 0; i < Screen.AllScreens.Length; i++)
                {
                    if (Screen.AllScreens[i].Bounds.Contains(r))
                    {
                        StartPosition = FormStartPosition.Manual;
                        Bounds = Prefs.Bounds;
                        break;
                    }
                }
                // FullScreen and others are set in Form1_Shown eventhandler
            }

            // Audio
            if (Prefs.SaveAudio || (Prefs.ContinuePlay && Prefs.MediaToPlay >= 0))
            {
                Player1.AudioVolume = Prefs.AudioVolume;
                Player1.AudioBalance = Prefs.AudioBalance;
            }

            // Position Slider
            if (Prefs.SaveSlider || (Prefs.ContinuePlay && Prefs.MediaToPlay >= 0))
            {
                SetSliderVisibility(!Prefs.SliderVisible);
                SetSliderProgress(Prefs.SliderProgress);
                SetSliderLiveUpdate(Prefs.SliderLiveUpdate);
            }

            // DisplayMode
            if (Prefs.SaveDisplayMode || (Prefs.ContinuePlay && Prefs.MediaToPlay >= 0))
            {
                if (Prefs.DisplayMode == DisplayMode.Manual)
                {
                    if(StartPosition == FormStartPosition.Manual) Player1.VideoBounds = Prefs.VideoBounds;
                    else Player1.DisplayMode = DisplayMode.ZoomAndCenter;
                }
                else Player1.DisplayMode = Prefs.DisplayMode;
            }

            // Speed
            if (Prefs.SaveSpeed || (Prefs.ContinuePlay && Prefs.MediaToPlay >= 0))
            {
                Player1.Speed = Prefs.Speed;
            }

            // Overlay - set in Form1_Shown
            // Repeat - set in Form1_Shown
            // FullScreen and others - set in Form1_Shown
        }

        private void SetDefaultPreferences()
        {
            Prefs.Version = PLAYLIST_VERSION;

            Prefs.SaveWindow = false;
            Prefs.Maximized = false;
            Prefs.Bounds = Bounds;
            Prefs.Fullscreen = false;
            Prefs.FullScreenMode = FullScreenMode.Display;

            Prefs.SaveAudio = false;
            Prefs.AudioVolume = 1000;
            Prefs.AudioBalance = 500;

            Prefs.SaveDisplayMode = false;
            Prefs.DisplayMode = DisplayMode.ZoomAndCenter;
            Prefs.VideoBounds = Rectangle.Empty;

            Prefs.SaveSlider = false;
            Prefs.SliderVisible = true;
            Prefs.SliderProgress = false;
            Prefs.SliderLiveUpdate = true;

            Prefs.SaveRepeat = false;
            Prefs.Repeat = 0;

            Prefs.AutoOverlay = true;
            Prefs.SaveOverlay = false;
            Prefs.Overlay = -1;

            Prefs.SaveSpeed = false;
            Prefs.Speed = 1000;

            Prefs.SaveMediaFilesFolder = false;
            Prefs.MediaFilesFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            Prefs.SavePlaylistsFolder = false;
            Prefs.PlaylistsFolder = Prefs.MediaFilesFolder;

            Prefs.ContinuePlay = false;
            Prefs.MediaToPlay = -1;
            Prefs.Position = 0;
            Prefs.StartPosition = 0;
            Prefs.EndPosition = 0;
            Prefs.Paused = false;
            Prefs.RewindSecs = 10;
            Prefs.VideoPresent = false;

            Prefs.PlayListShowExtensions = true;
            Prefs.PlayListChanged = false;
            Prefs.PlayListTitle = "Untitled";

            Prefs.AutoPlayStart = false;
            Prefs.AutoPlayAdded = true;
            Prefs.AutoPlayNext = true;
            Prefs.OnErrorPlayNext = true;
            Prefs.OnErrorRemove = false;
            Prefs.ShowErrorMessages = true;

            Prefs.ShowTooltips = false;
            Prefs.ShowMiniPlayers = false;
        }


        private void GetPreferences()
        {
            // Version
            Prefs.Version = PLAYLIST_VERSION;

            // Window
            Prefs.Fullscreen = Player1.FullScreen;
            Prefs.FullScreenMode = Player1.FullScreenMode;
            Prefs.Maximized = WindowState == FormWindowState.Maximized;
            //if (Player1.FullScreen) Prefs.Bounds = Player1.FullScreenRestoreBounds;
            //else Prefs.Bounds = WindowState == FormWindowState.Normal ? Bounds : RestoreBounds;
            Prefs.Bounds = Player1.FormRestoreBounds; // does same as both previous 2 lines

            // Audio
            Prefs.AudioVolume = Player1.AudioVolume;
            Prefs.AudioBalance = Player1.AudioBalance;

            // DisplayMode
            Prefs.DisplayMode = Player1.DisplayMode;
            Prefs.VideoBounds = Player1.VideoBounds;

            // Repeat
            if (RepeatOne) Prefs.Repeat = 1;
            else if (RepeatAll) Prefs.Repeat = 2;
            else if (RepeatShuffle) Prefs.Repeat = 3;
            else Prefs.Repeat = 0;

            // Position Slider
            Prefs.SliderVisible = sliderAlwaysVisibleMenuItem.Checked;
            Prefs.SliderProgress = sliderShowsProgressMenuItem.Checked;
            Prefs.SliderLiveUpdate = sliderSeekLiveUpdateMenuItem.Checked;

            // Display Overlay (stores the selected menu item - there are other ways to store the overlay)
            Prefs.Overlay = -1;
            if (Player1.Overlay != null)
            {
                for (int i = 3; i < displayOverlayMenu.Items.Count; i++) // find selected overlay menu item
                {
                    if (displayOverlayMenu.Items[i].GetType() == typeof(ToolStripMenuItem) && ((ToolStripMenuItem)displayOverlayMenu.Items[i]).Checked)
                    {
                        Prefs.Overlay = i;
                        break;
                    }
                }
            }

            // Speed
            Prefs.Speed = Player1.Speed;

            // Continue Play
            if (Prefs.ContinuePlay && Player1.Playing)
            {
                // save current media (playlist entry)
                Prefs.MediaToPlay = _mediaToPlay - 1;
                // save current position
                Prefs.Position = Player1.Position.TotalMilliseconds;
                // save startposition
                Prefs.StartPosition = Player1.StartPositionMedia.TotalMilliseconds;
                // save endposition
                Prefs.EndPosition = Player1.EndPositionMedia.TotalMilliseconds;
                // save paused
                Prefs.Paused = Player1.Paused;
                Prefs.VideoPresent = Player1.VideoPresent;
            }
            else
            {
                Prefs.MediaToPlay = -1;
            }

            // other options set elsewhere (Form1_Shown and some Prefs are used as 'normal' fields)
        }
    }
}

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