Articles Archive
Articles Search
Director Wiki
 

On the Web, Can Anyone Hear You Stream? Streaming Playback in Shockwave, Part I

March 20, 2001
by Darrel Plant

CNET Builder.com recently ran an article by David Emberton (lead author of the Flash Magic book series) comparing Director and Flash. Overall, it was evenhanded and well-informed, especially considering some of the invective on both sides of the Macromedia authoring tool debate, as long as you disregard the snide comments in the quiz accompanying the article.

One point caught my eye, however, and I fired off a quick email in response. In Emberton's discussion of one advantage of Flash over Director, he says: "In the beginning, streaming was one of the major advantages of Flash over Director. ... To keep up with multimedia trends, Director now has streaming capabilities."

A Sense of History

I should probably have just chalked this up to a certain amount of unfamiliarity with Director. Most Flash users haven't ever used the program, and for those folks who are coming to Director after first learning Flash (instead of the other way around), most of their experience is with movies that must download completely before they begin playback. As Emberton points out in his article, there are a lot of Flash developers who build movies that don't stream.

What set me off, of course, is that Director had a certain amount of streaming capability before there ever was a thing called Flash. Shockwave Audio files were introduced in the second incarnation of Shockwave -- for Director 5 --in 1996. That was back in the days when Shockwave wasn't built into the Director application. Back before the "Shockwave Studio". Shockwave movies were made from under the Xtras menu.

Dipping Into the Stream

Director 6 -- released in mid-1997 -- was the first version to integrate Shockwave movie creation into the File menu, and it was the first to include Network Lingo commands and functions in the popup menus. Among the entries there are things like frameReady, streamStatus, and tellStreamStatus, plus my favorite property: mediaReady of member.

A feature that's been around for three versions (four, if you count the 6.5 upgrade) isn't exactly "keeping up". In fact, Macromedia acquired Flash at the beginning of 1997, so streaming playback of Director movies has been around roughly as long as Flash has. Rather than complaining any more about a single item of information in a pretty complimentary article on Director, though, let's take a look at how streaming works and how you can use it in Director.

What is Streaming Playback?

Any Shockwave movie served from a Web server streams. Even on a fast connection, transmission of the movie data from the server to the client isn't instantaneous. But most developers choose to wait for an entire movie to download before playing.

The reason for this is that assets may not be available at the time they're needed by a playing movie. In a linear presentation with no scripts (like many early Flash movies or a simple digital video file), this isn't a problem. The player can display a frame, wait for the data of the next frame, then display it when it's ready. It's an automatic process, where one batch of data follows another in a pre-determined manner.

In a non-linear presentation, particularly one with interactivity, there's no way to predict what's going to happen. You can see the failure of this kind of system on almost any HTML page using scripted rollovers. If there are a lot of rollover buttons, and it takes some time to download the graphics, moving the cursor over a button whose rollover image hasn't downloaded yet results in the broken image icon showing up instead. The image hasn't been cached, yet the script is active, resulting in an error.

Director and Flash have much the same type of problem. Attempts to go to a frame that hasn't arrived yet or display a graphic that's still on its way will meet with failure. For a non-linear movie to stream during playback, there must be some method to determine which assets are available. With such a test, you can avoid any actions that you're not ready for. You need to add the intelligence to determine what can and can't be done. With more than one option, there's no way to predict which action a user might take.

Setup for Streaming

No movie's going to stream unless you tell it to. In the Movie Playback Properties dialog, you can specify whether the movie is going to play while it's downloading, how many frames of the movie must be downloaded before playback begins, and whether placeholder rectangles will be displayed for cast members that have not yet been downloaded.

The latter options aren't effective unless you've checked the first -- if you're not playing, you're not doing streaming playback. Without the Play While Downloading Movie option checked, the progress bar in the standard Shockwave download logo will fill completely before playback begins. Flash doesn't have any equivalent to these settings, it automatically assumes that the movie will stream during playback.

Structure of Streaming

To intelligently control streaming playback in a movie, you need to know something about how it's built. When you save a movie as a Shockwave DCR file, Director does more than just compress the source DIR file. It actually organizes the movie's data in a way that optimizes it for streaming.

In the first bytes of the file come two of the smallest and most compressible elements of the movie: the scripts and the data for the Score. This portion consists of compressed code, and data on sprite properties, behaviors, behavior properties, transitions and their settings, etc. Director doesn't have any tools like the handy Bandwidth Profiler in Flash for examining what the elements of the movie contribute to the final size of the Shockwave file, but these pieces are truly small compared to the data contained in a bitmap or sound file. These are the portions of the movie file that are needed for playback to begin.

The next portion of the file contains the data for media cast members, in the order that they're used in the Score. Cast members are only included in the file once.

The final portion of the file contains cast members that aren't included in the Score, in the order they appear in each cast library. Director includes everything from the DIR in the Shockwave DCR whether it's explicitly used in the movie or not. This places the onus of weeding out unused material from the cast on the developer, but since a Director developer is supposed to be smarter than the computer, that's better than leaving it up to an automated process.

Director's scheme is a bit different from Flash's. If a symbol (the Flash equivalent to a Director cast member) wasn't used in a timeline in Flash 4 or earlier, it wasn't exported. You can use Flash 5's Linkage dialog to force a symbol to be included in the SWF file. But linked symbols in Flash are placed ahead of the data for the frames, meaning that if there are a number of them, they can significantly impede the beginning of playback for the movie.

The diagram above gives a rough example of how a couple of equivalent movies are structured. Both movies contain several equivalent images that are not placed in the Score or Timeline. The first three frames (of four total) in each movie have scripts attached. The first frame of each movie has an image placed in it. The sequencing portion of the file contains Score or Timeline information.

Because the media in the Shockwave movie is placed at the end of the file, the movie can begin playing at a much earlier point of the download (indicated by the red arrow), if it's done correctly. All of the scripts and Score information have been downloaded by the time the first media element is streamed.

By contrast, a Flash movie of equivalent size must first wait for the linked library items to download before the first frame data is available for playback. There are ways around this -- using loaded external movies as containers for media, for example -- but it's just not as elegant.

Down(load) the Stream

As a Shockwave movie with streaming playback begins to download, the Shockwave Player receives the score data and the script cast members first. Then they're uncompressed and stored in memory.

The media cast members for each of the frames are received next. Once the Player has received the number of frames specified in the Movie Playback Properties dialog, playback begins. From that point on, it's up to the developer to ensure that Lingo doesn't try to access any cast members that haven't yet been downloaded. An error is generated otherwise. Flash relies on the file structure itself to accomplish the same task rather than leave it to the developer. By front-loading all of the media that can be referred to by ActionScript, it makes sure that scripting errors of that type can't happen, at the expense of a larger pre-playback download.

A Streaming Example

One of the first streaming movies I put together is the basis for this article. It's a fairly simple movie consisting of a 4x4 grid of images simulating a "video wall" effect, with transitions consisting of changing rows, columns, and spirals.

Each transition consists of one or more images being replaced by another, from a list of up to 102 available images. The movie can begin playing with only a few images loaded, however, as most of the images aren't placed in the Score, and playback is set to begin after only one frame is downloaded. Oh, and there's some cool surf music (courtesy of Oregon's own The Surf Trio) streaming as an external Shockwave Audio file.

Take a look at the sample movie. (approximately 700k download)

In the next installment, we'll take a detailed look at how it can be done. A hint: it's the mediaReady property.

Darrel Plant is Technical Editor of Director Online. He is the Publisher at Moshofsky/Plant Creative Services in Portland, Oregon, and the author of or contributor to a number of books on Macromedia Director and Flash, including Special Edition Using Flash 5,, Flash 5 Bible, and Director 8.5 Studio..

Copyright 1997-2017, Director Online. Article content copyright by respective authors.