Adding the ability to play embedded QuickTime media in .NET applications is fairly easy using the QuickTime COM/ActiveX Control provided by Apple as part of their QuickTime for Windows player software. However, although the online documentation for the QuickTime Framework is quite extensive and detailed, the COM/ActiveX section leaves much to be desired, especially if it comes to the initial installation and setup.
It is assumed that you have a working installation of Visual Studio 2005 or Visual C# 2005 Express Edition and the .NET Framework 2.0 or newer. In addition to that, you also need to:
- Download and install Apple's QuickTime for Windows (note that the version for Windows 2000/XP also works on Windows Vista)
QuickTime Player comes with all the additional components for developers. iTunes is not required to play QuickTime media, so you can safely get the version without it. It is also not required to upgrade to the commercial 'QuickTime Pro' version. The free player installation will work just fine.
Adding the QuickTime Control to Visual Studio
Before you can start using QuickTime in your applications, you have to add the QuickTime COM/ActiveX Control to Visual Studio. The following steps apply specifically to Visual C# 2005 Express Edition, but the setup will be similar for Visual Studio 2005:
- Open the Visual Studio Toolbox (if it is not already open, you can open it by selecting Toolbox from the View menu)
- Right-click any category in the toolbox (e.g. General) and select Choose items... to open the Choose Toolbox Items window.
- In the Choose Toolbox Items window select the COM Components tab.
- In the list of COM components set the checkbox for Apple QuickTime Control 2.0.
You can now drag the Apple QuickTime Control from the toolbox and drop it onto any of your forms. By default it will show an empty panel with the QuickTime logo.
If you're on a 64-bit platform, such as Windows XP 64-bit or Windows Vista 64-bit, things are a little more complicated. Most existing COM components (including the QuickTime Control for Windows) have been written for 32-bit applications and will not run in 64-bit processes on a 64-bit platform.
Since .NET applications running on a 64-bit system will automatically be launched in a 64-bit process, they will fail to work properly if 32-bit components are being referenced, resulting in runtime exceptions, such as Class not registered or Cannot instanciate class.
The solution is to change the target platform of your .NET application to 32-bit, so that it will run in the WOW64 compatibility mode on 64-bit platforms. Visual Studio 2005 provides a project setting for this purpose:
- Right-click your project in the Solution Explorer and select Properties...
- Select the Build tab
- Change the Platform Target property to x86.
In Visual C# Express Edition this project setting is not exposed. However, it is possible to change it in the project file:
- Close your project and/or solution
- Open the project's .csproj file in a text or XML editor
- Locate the first
- Add the following line in this section:
- Save the project file and reload the project.
Eventually, Apple will provide 64-bit versions of their components in the future, so that this workaround will no longer be necessary.
Now that the QuickTime control is installed properly, you should have no difficulties developing your own .NET applications with embedded QuickTime media support. Simply drop the Apple QuickTime Control 2.0 onto your form and start using it just like any other Windows Forms component.
The QuickTime control provides various properties exposed in the Properties Window that allow you to configure its basic appearance and behavior. Most runtime functionality, however, will only be accessible through the Interop.QTOLibrary namespace. You can explore the wide range of interfaces and classes in Visual Studio's Object Browser.
Please download the following ZIP archive containing a small sample project written in C#. It demonstrates how to load and play a movie:
QuickTimeExample.zip (62.2 kB).