QuickTime 7 for Windows introduces a completely new COM/ActiveX control that is fully scriptable from Visual Basic, C#, JavaScript, C++ and other applications that can host COM objects. This means that its even easier for Windows programmers to build standalone Windows applications that use QuickTime without needing to master QuickTime's C/C++ API. Important: This new COM control is included in addition to the QuickTime ActiveX browser plug-in. They are not the same thing The new QuickTime COM control has an API that will be familiar to Visual Basic programmers and others used to working with COM objects. It is intended to make it easy to create stand-alone Windows applications that use QuickTime. The new COM control is not a browser plug-in, and will not run in a browser or other Web-based application. For Web-based applications, use the QuickTime ActiveX browser plug-in; it is scriptable using JavaScript from most browsers using the same platform-independent API as the QuickTime browser plug-ins for Netscape and Safari. The QuickTime browser plug-in is the cross-platform solution for Writing Web pages that interact with QuickTime. Note: The API for controlling the QuickTime ActiveX browser plug-in using JavaScript can be found in the JavaScript Scripting Guide for QuickTime. The remainder of this article is intended for programmers who want to provide high-level QuickTime movie playback and control, including some import, export, and editing capabilities, to Windows applications written in Visual Basic and other languages. Advantages For DevelopersIf you are a Visual Basic programmer or enterprise software developer doing in-house development, the COM control implementation offers a number of important advantages:
For example, if your Windows server can run a Visual Basic, C#, or script application that uses QuickTime, you have the possibility to create custom QuickTime content interactively, delivering that content over the Web. As long as your clients have QuickTime installed, your content will work with Windows and non-Windows clients, Internet Explorer and non-Internet Explorer browsers. QuickTime Player itself uses the new QuickTime COM control for virtually all of its access to QuickTime. Important: The QuickTime 7 ActiveX browser plug-in is not scriptable via Visual Basic. It is scriptable, however, in JavaScript using the same syntax as the Netscape-style plug-in, and works the same on all browsers for Windows or Macintosh. How It WorksThe new COM control is comprised of two separate DLLs:
The COM library is a very thin layer that sits on top of the low level QuickTime APIs and provides a COM wrapper object for each logical QuickTime object. Each COM object exposes the properties, methods, and notifications of the QuickTime object it wraps. The object hierarchy is illustrated in Figure 1. Figure 1: The COM/ActiveX Control Object Hierarchy If you are a Windows developer, you know that the Component Object Model (COM) specification defines how a host application accesses the component, how the component notifies the host application of events, standard data types for data exchange with the OS or other components. A COM control is a type of COM component that has a visual display of some kind, restricting its placement to visual containers such as a form or dialog box. COM controls typically manage their own window. In the .NET environment, the new QuickTime COM control is accessed via the .NET Framework's COM Interop layer. Primary Interop Assemblies (.NET wrappers for COM objects) will be provided with the QuickTime 7 SDK. Note: The COM control does not provide a native .NET managed code interface to QuickTime. Visual Basic .NET and C#You will use the QuickTime COM control and its various methods from Visual Basic .NET and C# as described in the following sections. BasicsOnce you instantiate the QuickTime COM control and load a movie into it, you can then get at the QTOLibrary object model via the control's Movie property, which returns a QTMovie COM object. Constants and EnumerationsTo use the constants and enumerations associated with the QuickTime COM control, you must either explicitly precede them with the QTOControlLib namespace identifier, or else include an import for the QTOControlLib. In Visual Basic, you do this with an Imports directive at the beginning of your module. An example of using an explicit namespace identifier is, as follows: AxQTControl1.Sizing = QTOControlLib.QTSizingModeEnum.qtControlFitsMovie AxQTControl1.SetScale(2) AxQTControl1.Sizing = QTOControlLib.QTSizingModeEnum.qtMovieFitsControl The same example with imported namespace: Imports QTOControlLib AxQTControl1.Sizing = QTSizingModeEnum.qtControlFitsMovie AxQTControl1.SetScale(2) AxQTControl1.Sizing = QTSizingModeEnum.qtMovieFitsControl In C#, the namespace can be imported with the using QTOControlLib; To use the constants and enumerations associated with the QuickTime COM library, you must either explicitly precede them with the QTOLibrary namespace identifier, or else include an import (C#: using directive) for the QTOLibrary. Getting Started With QuickTime COM Control And Visual Basic 6In the next few sections we'll build a simple movie player application in Visual Basic 6 which will include the following capabilities:
The project will be built in a series of steps, starting with simple movie playback using a movie controller. Successive steps will add new capabilities to the project, each building on the previous step. Project 1: Simple Movie Playback Using a Movie ControllerTo get started with the new COM control in Visual Basic 6:
Figure 2: The QuickTime COM Property Page Dialog
Figure 3: Updated QuickTime Control Property Settings
Figure 4: Simple Movie Player with Movie Controller
As you can see, with just a few simple steps and no real coding we've created a simple movie player application which displays a movie along with a controller in a window. Now we'll look at how to create some more sophisticated applications using the QuickTime COM Control. Project 2: Movie Open, Open URL and CloseIn this next step, we'll add to our application the ability to open and close movie files on disk and from a URL. More specifically, we'll add a File->Open menu item to allow us to open any movie file on disk. Similarly, we'll add a File->Open URL menu item to allow us to open any movie URL. Finally, we'll add a Close menu item to allow us to close any opened movie. Follow these steps:
Listing 1: The GetFileName function to display a file open dialog Function GetFileName() CommonDialog1.ShowOpen GetFileName = CommonDialog1.FileName End Function
Listing 2: File Menu Handling Code Private Sub mnuFile_Click(Index As Integer) Select Case Index Case 0 'Open Dim fname As String fname = GetFileName() If fname < > "" Then QTControl1.URL = GetFileName() End If Case 1 'Open URL Dim movieURL As String movieURL = InputBox("Enter a URL:", "URL", "http://www.server.com/movies/sample.mov") If movieURL < > "" Then QTControl1.URL = movieURL End If Case 2 'Close QTControl1.URL = "" End Select End Sub After you have completed these steps, you can:
Figure 5: SimplePlayer with File Menu Project 3: Simple EditingNow we'll add some simple editing capabilities to our project - the ability to perform Undo, Cut, Copy and Paste. Follow these steps:
Listing 3: Edit Menu Code Private Sub mnuEdit_Click(Index As Integer) Select Case Index Case 0 'Undo If QTControl1.URL < > "" Then QTControl1.Movie.Undo End If Case 2 'Cut If QTControl1.URL < > "" Then QTControl1.Movie.Cut End If Case 3 'Copy If QTControl1.URL < > "" Then QTControl1.Movie.Copy End If Case 4 'Paste If QTControl1.URL < > "" Then QTControl1.Movie.Paste End If End Select End Sub After you have completed these steps, you can:
Figure 6: SimplePlayer with Edit Menu Project 4: Movie ExportIn this project, we'll show how to use the QuickTime movie exporters to display the export dialog and save our movie to a different format. Follow these steps:
Listing 4: Movie Export Code Case 4 'Export' If QTControll.Movie Is Nothing Then Exit Sub If QTControll.Movie.canExport Then Dim qt As QTOLibrary.QTQuickTime Set qt = QTControl1.QuickTime If qt.Exporters.Count = 0 Then qt.Exporters.Add End If Dim exp As QTOLibrary.QTExporter Set exp = qt.Exporters(1) exp.SetDataSource QTControl1.Movie exp.ShowExportDialog End If After you have completed these steps, you can:
Figure 7: Movie Export Dialog Project 5: Full Screen Movie DisplayIn this project, we'll show how to display QuickTime movies that fill the entire screen. Follow these steps:
Listing 5: Turning on Movie Full Screen Playback ... Case 5 'FullScreen QTControl1.FullScreen = True
Listing 6:Handling Movie Full Screen Begin/End Private Sub QTControl1_StatusUpdate(ByVal statusCodeType As Long, ByVal statusCode As Long, ByVal statusMessage As String) Select Case statusCodeType Case qtStatusCodeTypeControl Select Case statusCode Case qtStatusFullScreenBegin Me.Hide ' hide movie window Case qtStatusFullScreenEnd ' set movie back to a reasonable size QTControl1.SetScale 1 Me.Show ' show movie window again End Select End Select End Sub
Figure 8: Movie Full Screen Playback
ConclusionAs you can see, the new QuickTime 7 COM/ActiveX control is quite simple to use and gives developers convenient access to the underlying QuickTime framework. Now more than ever this makes it easier for Windows programmers to build standalone Windows applications that use QuickTime without needing to master QuickTime's extensive C/C++ API. For More InformationPosted: 2005-09-12 |