Welcome all! I wrote earlier a tutorial about playing audio files using mciSendString method. While it is a reasonable solution, I really prefer to use Managed DirectX. It gives much more control over what is happening. And besides, no crazy P/Invoke signatures are required. Therefore I decided to make a tutorial about it too, and let you be the judge. Enjoy reading.
Playing video with Microsoft.DirectX.AudioVideoPlayback namespace
Before you read further take this warning. If you are using Managed DirectX then not every computer will be able to run your program right away. The program will require both .NET Framework and DirectX installed. The problem arises when I add that DirectX has to be installed after .NET Framework, not before it. This is because it will also install Managed DirectX assemblies which are now among dependencies.
First thing to do is to add a reference. Open Solution Explorer and add the dependency. Then you are also going to need the same namespace. Just look at the screenshots below.
![]()
Playing video in control mode
This code starts playing the video in a Panel that I put into the form. I did not make an open dialog, though. I think just a Textbox will do.
Code:Video video = new Video(FilenameTextbox.Text); video.Owner = panel1; video.Play();
Playing video in external window mode
This code starts playing in an external window. If you close that window then audio will still be playing. To stop playing there is the Video.Stop method.
Code:Video video = new Video(FilenameTextbox.Text); video.Play();
Playing video in fullscreen mode
The last piece of code will play in fullscreen mode. Again, pressing Alt+F4 will close the video but audio will go on.
Code:Video video = new Video(FilenameTextbox.Text); video.Fullscreen = true; video.Play();
Author thanks you for comments
I hope you enjoyed reading my tutorial. If it was helpful or useful then even more so. Feel free to post a comment or drop me some +rep. I thank you in advance.![]()


LinkBack URL
About LinkBacks











Reply With Quote








Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum