Accessibility
Tony Knight

Tony Knight

Macromedia

Created:
17 May 2004
User Level:
Beginner
Products:
Director

Using Flash to Control DVD Movies

New DVD playback features in Director MX 2004 have opened the door for developers to create sophisticated web-controlled DVD projects using Shockwave Player 10. By leveraging DVD video playback with web browser control, Director developers can now extend the functionality of DVD video beyond the set-top box to a number of new applications, including distance learning, entertainment, and corporate presentation.

Recently, I came across a developer who wanted to use Shockwave Player to play DVD video inside an HTML page, but he also wanted the flexibility to add custom Macromedia Flash-based DVD controls outside of the rectangle of the Shockwave project.

Not a problem, I thought. While it's well-known that Director can send and receive messages to and from Flash content inside Director projects, many developers don't know that external Macromedia Flash files (SWFs) can also control Director content. In this article, I will demonstrate using Flash content to control DVD playback, even if it is located outside the Shockwave file.

Requirements

To complete this tutorial you will need to install the following software and files:

Director MX 2004

Tutorials and sample files:

Background

Director MX 2004 includes an Xtra called the DVD Event Manager. Developers can use this tool to rapidly build certain enhanced DVD functionality while eliminating the need for scripting. One of the features of the DVD Event Manager is to attach a prebuilt Flash-based DVD controller to DVD cast members. This controller has the ability to enable a Flash feature called LocalConnection. LocalConnection lets you quickly and easily send and receive messages to and from other Flash movies. When you enable LocalConnection from within the DVD Event Manager, the DVD Controller becomes a conduit that receives DVD control information from external Flash movies and passes it on to the DVD cast member for execution. Conversely, the DVD controller also acts as a broadcaster; passing along events from DVD playback to external Flash movies.

By using LocalConnection as an intermediary, a Director developer can create a browser-based DVD player that can be continually updated with Flash content for custom navigation. I'll review how to build a small sample project that demonstrates this usage scenario.

Preparing for the Connection

The first step in enabling Flash control over DVD playback is to create a Shockwave movie that will act as a intermediary.

  1. Ensure that you have the DVD Event Manager installed with Director MX 2004. The DVD Event Manager is located in the Goodies folder of the Director MX 2004 CD. If you don’t have the CD handy, or if you purchased Director MX 2004 electronically, you can download the Goodies folder here:

    http://macromedia.com/support/director/downloads.html

    Once you have the Goodies folder, drop the DVD Event Manager DCR file into your Director Xtras folder to install it. Next you will create a simple DVD playback project with which the Flash movies can communicate.

    Put a DVD movie into your PC’s DVD-ROM drive and launch Director MX 2004. You are going to create a project with the dimensions of 400 x 380 pixels.

  2. Open the DVD Event Manager. Click the New DVD Cast Member button. Create and name a new DVD cast member and set its properties. Once you create the new cast member, click the Use Local Connect button. Click to the third pane of the interface. Go to the Cast window and drag both the DVD cast member and the DVD controller to the Stage. Once you have done so, go back to the DVD Event Manager and click the Add Scripts button of the Final Stage pane. This will bind the DVD cast member to the Flash-based controller and turn on the LocalConnection receiver and broadcaster.

    Close the DVD Event Manager, resize the DVD cast member to 400 x 300 pixels, and position the controller below the DVD. This is pretty much all you have to do inside Director. Select Publish Settings > File and make sure you have the Shockwave and HTML output options enabled in the Publish Settings dialog box. In this project, you just need the Shockwave project with the corresponding HTML wrapper. Save the settings and publish the content. When you open the HTML file with a Shockwave 10-enabled browser, you should see a DVD movie with a fully functional controller as shown in Figure 1 below.

The index.html page, a web page with two frames

Figure 1. A DVD movie with a fully functional controller

Developing DVD Controls with Flash

So far you have created, in fairly short order, a small Shockwave-based DVD player, which has LocalConnection turned on. This means that the DVD cast member will broadcast events to any Flash movie on the local machine, and it will also receive messages from any local Flash movie. Now you are going to look at a Flash movie that can take advantage of these features.

Open the dvd_localconnection.fla file that is contained in the sample files linked from the beginning of this article. This is a very simple project that demonstrates how to initiate a LocalConnection and how to pass messages to the DVD player inside Shockwave. First, take a look at the ActionScript code in Frame 1 of the Code layer:

function initConnection()
  {
	  // Init receive connection.
	  this.connectionReceiveName = "receive_connection";
	  this.receive_lc = new("LocalConnection");
	  this.receive_lc.replyMethod = function(xParameter)
	  {
		  // trace("RECEIVED REPLY " + xParameter);
		  var tOutput = ("RECEIVED REPLY " + " result = " + xParameter);
		  // If it's an array, then trace the values.
			for (var tsProp in xParameter)
			{
				tOutput = tOutput + "\r" + tsProp + " = " + xParameter[tsProp];
				// trace(tsProp+" = "+xParameter[tsProp]);
			}
			_root.replyOutput.text = (tOutput + "\r" + _root.replyOutput.text);
	  }
	  this.receive_lc.connect(this.connectionReceiveName);
	  // Init send connection.
	  this.connectionSendName = "toDvd";
	  this.send_lc = new("LocalConnection");
  }
//--------------------------
function closeConnection()
  {
	  this.receive_lc.close();
  }
//--------------------------
function testCallMethod(xMethod, xParameter1, xParameter2)
  {
	  var tCall = "lc_dvdCallMethod";
	  var tReplyConnection = this.connectionReceiveName;
	  var tReplyMethod = "replyMethod";
	  var tSendConnection = this.connectionSendName;
	  var tSuccess = this.send_lc.send(tSendConnection, tCall, tReplyConnection, tReplyMethod, xMethod, xParameter1, xParameter2);
	  return tSuccess; 
  }
//--------------------------
function testSetProperty(xProperty, xValue)
  {
	  var tCall = "lc_dvdSetProperty";
	  var tReplyConnection = this.connectionReceiveName;
	  var tReplyMethod = "replyMethod";
	  var tSendConnection = this.connectionSendName;
	  var tSuccess = this.send_lc.send(tSendConnection, tCall, tReplyConnection, tReplyMethod, xProperty, xValue);
  	  return tSuccess; 
 }
//--------------------------
function testGetProperty(xProperty)
  {
	  var tCall = "lc_dvdGetProperty";
	  var tReplyConnection = this.connectionReceiveName;
	  var tReplyMethod = "replyMethod";
	  var tSendConnection = this.connectionSendName;
	  var tSuccess = this.send_lc.send(tSendConnection, tCall, tReplyConnection, tReplyMethod, xProperty);
  	  return tSuccess; 
 }
//--------------------------
function testGetStatusArray()
  {
	  var tCall = "lc_dvdGetStatusArray";
	  var tReplyConnection = this.connectionReceiveName;
	  var tReplyMethod = "replyMethod";
	  var tSendConnection = this.connectionSendName;
	  var tSuccess = this.send_lc.send(tSendConnection, tCall, tReplyConnection, tReplyMethod);
 	  return tSuccess; 
  }

These six functions initiate the LocalConnection and set up the link from which the messages will be sent and received from the DVD Player. Back in Director, the DVD Event Manager created a LocalConnection with the name ToDVD. This named connection is now used by Flash to pipe a connection between the DVD controller and any other Flash movie that can initiate a connection with that name. Notice also that in Frame 2 of the action layer there is a bit of ActionScript that stops the LocalConnection after a function has been called.

The real heart of this project's functionality lies in the five buttons below the output console. Here is a description of each, along with the code:

Status: When released, this button calls the testGetStatusArray function and returns the status of the DVD player state. It returns the results to the output console.

on(release)
{
  var tSuccess = _parent.testGetStatusArray();
}

Play: When released, this sends a play command to the DVD Player by calling the testCallMethod function.

on(release)
{
  var tSuccess = _parent.testCallMethod("play");
}

Pause: When released, this sends a pause command to the DVD Player by calling the testCallMethod function.

on(release)
{
  var tSuccess = _parent.testCallMethod("pause");
}

Clip: When this button is released, it sends a message to the DVD player to create a start and stop time for the DVD cast member, and then it plays it. In this example, you are jumping 10 seconds and one frame into Title 1, and then stopping seven seconds later.

on(release)
{
  var tStart = Array("title", 1, "hours", 0, "minutes", 0, "seconds", 10, "frames", 1);
  var tStop = Array("title", 1, "hours", 0, "minutes", 0, "seconds", 17, "frames", 1);
  var tSuccess = _parent.testCallMethod("play", tStart, tStop);
}

Time: When this button is released, it calls the testGetProperty function and returns the CurrentTime of the DVD to the output console.

on(release)
{
  var tSuccess = _parent.testGetProperty("currentTime");
}

Set Chapter: When released, this button calls the testSetProperty function requesting a chapter jump to chapter 3.

on(release)
{
  var tSuccess = _parent.testSetProperty("chapter", 3);
}

As you can see, controlling DVD playback from within Flash is simple when using the DVD Event Manager and LocalConnection-enabled Flash content. Using this sample code, you can access all of the DVD playback and navigation functions of Director MX 2004 through Flash.

If you open the index.html page (Figure 2), you will see a web page with two frames. The left frame contains the Shockwave content, while the right frame contains the Flash movie I have just been referring to. Your pages don’t necessarily have to be in frames for this to work. With LocalConnection, the Flash movie just needs to be on the same machine as the DVD player. In fact, while writing this article, I had the DVD movie playing inside Safari, while I was passing methods and setting properties to it from inside the Flash authoring application.

The index.html page, a web page with two frames

Figure 2. The index.html page, a web page with two frames

(+) View Larger

Conclusion

For developers of web-connected DVDs, the ability to control DVD playback through Flash is important for several reasons. First, it gives website designers a greater degree of flexibility in creating their content. Rather than having to place controls and other navigation widgets in the confines of their Shockwave files, they have the freedom to place the Flash content wherever they want. Also, designers can quickly create DVD navigation content on their sites without having to make modifications to their Shockwave content.

Using the DVD Event Manager with LocalConnection, Flash content provides an easy approach to maximizing design flexibility and providing the richest web-connected DVD experience.

About the author

Tony Knight is a 15-year veteran of the multimedia industry; taking on diverse roles ranging from software engineering to product management. He served as Apple's QuickTime Evangelist in the mid-90's before starting a DVD technology company called SpinWare. Most recently, he served as the product manager for Apple's DVD Studio Pro, and as the senior product manager for Macromedia Director MX 2004. When not launching products or creating DVDs, Tony loves to travel to France and spend time with his fiancée.