Click here to Skip to main content
15,885,546 members
Articles / Programming Languages / C#
Article

C# Movie Player

Rate me:
Please Sign up or sign in to vote.
4.89/5 (51 votes)
21 May 2007CPOL3 min read 421.6K   29K   167   71
Managed DirectX movie player
Screenshot - zmovieplayer.jpg

Introduction

After I found that my previous movie player was broken by all the changes done to Vista, I started looking for a C# solution based on managed DirectX.

Everything I tried with the original Vista failed, until I downloaded the latest Microsoft DirectX 9L version from April 2007 that solved all my Vista problems.

Thus in order to use this code with Vista (no problem running it under XP), you must first download the latest DirectX SDK from here.

Then you will be able to use the Microsoft.DirectX.AudioVideoPlayback assembly.

Documentation

Once you have installed the full DirectX SDK, and assuming you have installed it with the default setup, you can find the documentation about the AudioVideoPlayback assembly in this folder:
C:\Program Files\Microsoft DirectX SDK (April 2007)\Documentation\DirectX9\directx9_m.chm.

Using the Player

zMoviePlayer is able to play: AVI, MPG, MPEG, WMV, DivX, Xvid (assuming that you have installed the right CODEC first).

While in "full screen" mode, move the mouse to the bottom to show/hide the "command panel".

To select a movie, use either the Menu to popup the common dialog file selector, or use Drag & Drop from the Explorer onto the zMoviePlayer form.

Using the Code

The main DirectX class of the player is named Video and it is very easy to use.
You can get all the details about it from the Visual Studio popup contextual menu (get definition).

Because I wanted to have a nice looking interface "a la WMP 11", I have added a few classes myself to perform the skinning of the player. They are:

  • SkinButton.cs - User control to create skinned button using one single 5-image bitmap matching each of the button states: normal, down, disabled, focused, hover.
    You can use either "standard" push button or shaped button with region.
  • SkinTrackbar.cs - User control to create a mouse only skinned track bar. The thumb tracker can have any size or shape based on a provided bitmap. The control orientation is based on the ratio between width and height, if width is larger than height, then horizontal else vertical. To help the user figure out the moving of the thumb track, the control uses different colors to show the current value. You can inverse ranging swapping min/max values.
  • SkinEngine.cs - This class is responsible for the drawing of the skinned controls.

Points of Interest

To get rid of the "loaderlock" exception message while running in the Visual Studio environment:
Use "Ctrl + Alt + E" to open the Exceptions dialog box, select "Managed Debugging Assistants" and uncheck "Loaderlock".

History

Updated on 05-22-2007 (version 1.04)

  • COMMAND line support (works also to drag movie file from Explorer onto the player's desktop icon if any)
  • PROCESS DETECTION: see IsAlreadyRunning()
  • ICONIC mode detection to restore original location (when the command line is being used)
  • AUDIO LEVEL saved between sessions
  • New label ShowTime (to see the current time while running in full screen mode)
  • Private WM_STRINGDATA message to play a new movie, using command line file name

Updated on 05-15-2007 (version 1.03)

  • This version saves the latest folder being used into the registry and retrieves it between sessions to ease movie selection (very handy when all the movies are stored into the same folder inside a dedicated sub-folder sorted by movie type).
  • HD movies (WMV HD movies do not work on Vista)
  • MUTE problem has been fixed (MUTE was ignored when playing a new movie even when ON)

See My Other C# Demos

http://www.zapsolution.com/winlift/ccorner.htm - Make sure to try the "carousel" demo!

Patrice Terrier
www.zapsolution.com

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer zapsolution
France France
I am a low level SDK programmer, focusing mainly on graphic imaging and multimedia applications.
I am using several languages, including C, C++, PowerBASIC, WinDev.
I wrote also a few demos in C#, but i never used DotNET in real code production.

Comments and Discussions

 
Generalcontrol movie speed Pin
cekasp22-May-07 1:44
cekasp22-May-07 1:44 
GeneralRe: control movie speed Pin
Christopher Stratmann22-May-07 1:46
Christopher Stratmann22-May-07 1:46 
GeneralRe: control movie speed Pin
zapsolution22-May-07 4:13
zapsolution22-May-07 4:13 
GeneralRe: control movie speed Pin
zapsolution22-May-07 4:06
zapsolution22-May-07 4:06 
Generalcool Pin
American_Eagle22-May-07 1:09
American_Eagle22-May-07 1:09 
GeneralUpdated on 05-22-2007 to version 1.04 Pin
zapsolution21-May-07 21:31
zapsolution21-May-07 21:31 
GeneralDirectShow Issues.. Pin
Robert Cooley15-May-07 6:21
Robert Cooley15-May-07 6:21 
GeneralUpdated on 05-15-2007 to version 1.03 Pin
zapsolution15-May-07 3:42
zapsolution15-May-07 3:42 
GeneralAdditional question: show a spezific frame Pin
StephanG14-May-07 21:44
StephanG14-May-07 21:44 
GeneralRe: Additional question: show a spezific frame Pin
zapsolution14-May-07 22:03
zapsolution14-May-07 22:03 
GeneralWmv HD format Pin
zapsolution14-May-07 4:00
zapsolution14-May-07 4:00 
GeneralUnhandled exception Pin
Theooo11-May-07 20:08
Theooo11-May-07 20:08 
GeneralRe: Unhandled exception Pin
zapsolution11-May-07 21:52
zapsolution11-May-07 21:52 
GeneralRe: Unhandled exception Pin
BuBBleS816-Jun-07 13:28
BuBBleS816-Jun-07 13:28 
GeneralManaged Solution Pin
Muhadeeb993-May-07 1:48
Muhadeeb993-May-07 1:48 
GeneralBeautiful Pin
kclteam1-May-07 16:29
kclteam1-May-07 16:29 
QuestionEffects? Pin
bytecarp1-May-07 7:25
bytecarp1-May-07 7:25 
AnswerRe: Effects? Pin
zapsolution1-May-07 8:16
zapsolution1-May-07 8:16 
GeneralRe: Effects? Pin
bytecarp1-May-07 9:01
bytecarp1-May-07 9:01 
GeneralRe: Effects? Pin
zapsolution1-May-07 9:10
zapsolution1-May-07 9:10 
GeneralSource code updated on 05-01-2007 Pin
zapsolution30-Apr-07 22:58
zapsolution30-Apr-07 22:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.