Embedding QuickTime Media into .NET Applications using Visual C#
This article is part of a backup. It was originally posted on Friday, February 23. 2007.
Adding the ability to play embedded QuickTime media in your .NET application 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. This article provides a detailed description on how to get started, and it also resolves the difficulties you will encounter when developing for 64-bit platforms.
Requirements
In the following paragraphs 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 will also have to have the following:
- Download and install Apple’s QuickTime for Windows. Please 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 with your mouse on 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.
64-bit Notes
If you’re working 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 errors or exceptions, such as “Class not registered” or “Cannot instanciate class”. The solution to this problem 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 <PropertyGroup> section.
- Add the following line in this section: <PlatformTarget>x86</PlatformTarget>
- 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.
Sample Application
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 (60.3 kB)
Hi. I just run into your blog and this article solved my problem! I am a newbie to all COM + QuickTime + C#, and am using x64 machine. I got “class not registerd” error all the time, almost give up to develop a software… I just switched to x86 and it worked!
Anyways, thanks to your information!