9.2. Controlling External VideosIn this section, you will learn how to use components to control external video, and how to write your own control scripts. Using external video in Flash is very similar to using external sound. The major difference between external video and external sound is that FLV video files are only used by the Flash platform, making them a bit harder to create and repurpose than MP3 audio files. Fortunately, a variety of tools exist to create FLV files, including two that ship with Flash. 9.2.1. EncodingThe most rudimentary way to encode videos into FLV format is to use the Import Video Wizard, just as you did during the "Preparing Video for Import into Flash" section of this chapter. This may not make sense given the name of the wizard, but the same process you used earlier can also create external FLV files. Instead of embedding the video, the wizard will create an external FLV and configure your new file with the new FLVPlayback component. Note: Depending on the source material, the speed of your computer, and the software you are using, it can take a long time to encode a video into FLV format. If you are most interested in the step-by-step process of this project and wish to leave the long encoding process until later, you have two options. First, you can use the small video you imported in the previous section, extreme_sports_ loop.mov, instead of the suggested nero.mov. Second, you can read this section without following the steps and use the nero_01.flv file provided on the CD-ROM in the 09 folder. Flash's Import Video Wizard saves external video files in the same location as the currently active document. Therefore, you must have a recently saved file open for the wizard to determine an export path. Here's how it works:
Your file should publish very quickly (because all assets are external) and show the video, complete with controller, for you to use. You will learn how to configure options of the controller in an upcoming section of this chapter. 9.2.2. Standalone encoding applicationsWhile it's convenient to encode FLV files from within Flash, doing so can take longer and yield poorer results than encoding with a dedicated FLV compression tool. Fortunately, two additional pieces of software ship with Flash 8 Professional. The first is the Flash 8 Video Encoder. Essentially, this is a standalone version of the encoder built into Flash. However, it appears to produce better results faster, and it offers the huge benefit of supporting batch processing. The interface, beyond the batch-processing window, is the same for the most part. The second piece of software is the Flash 8 Video Exporter. During the installation of Flash 8 Professional, the Exporter is installed and made available to any QuickTime-savvy application. Although, as a codec, it can't offer batch processing, it can be handy to export to FLV from within your favorite video editing application. The Exporter, too, shares essentially the same interface as Flash's Video Import Wizard and the Flash 8 Video Encoder. Third-party tools are also available. Although requiring an additional purchase, they typically offer better, faster results than the aforementioned solutions that ship with Flash. There are two major tools in this market, but others exist. The companion web site to this book, http://www.flash8projects.com, will host a regularly updated list of Flash resources that will include additional information about encoders. The first major third-party tool is Sorenson Squeeze. As the developers of the original Flash video codec, Sorenson Spark, they have experience compressing for Flash and have created a sturdy tool that is also easy to use. At the time of this writing, Sorenson had announced support not only for their own Spark codec, but for On2's VP6 codec, making it possible for Squeeze to compress FLV files that take full advantage of Flash 8's features. See Appendix A for more information about Squeeze. The second major third-party FLV compression application is the Flix Flash 8 Video Encoder, by the makers of the Flash 8 video VP6 codec, On2. Flix is a powerful, feature-rich tool that offers a host of features, including expanded file support and the ability to vectorize video for interesting effects. Most notable, however, is the fact that the version of Flix that was current as of this writing compressed files that were as much as 25% to 30% smaller than those produced by any other exporter. See Appendix A for more information about Flix. 9.2.3. Streaming Versus Progressive DownloadTalk about streaming video abounds, but unless you're using dedicated streaming server software, you're probably not working with streaming video. Instead, you are probably working with a pseudo-streaming technology sometimes called fast start or quick start. These technologies effectively pre-fetch or buffer a portion of the video and then allow playback while downloading the remaining content. This approach is also commonly called progressive download, because the asset is downloaded in progressive stages without affecting playback too much. FLV files encoded for progressive download can also be used locally, and these will be the focus of the video projects in this book. The Flash platform includes a streaming server, currently called Flash Media Server 2. (Until recently, it was called the Flash Communication Server.) Use of this server is outside the scope of this text, but additional information is available online, including at Macromedia's web site (http://www.macromedia.com/software/flashmediaserver/). 9.2.4. FLV ComponentsThe FLVPlayback component is the new Flash 8 version of the media components you used in Chapter 8. It only works with FLV files, not MP3 files. Even if you ended up with a working component after the in-Flash video encoding example, start from scratch now to see how easy the FLVPlayback component is to use:
That's all there is to it. You should now be able to control your external video with the controller, as seen in Figure 9-4. There's one important thing to know about the FLVPlayback component, though. The controller is an external .swf file that is automatically loaded by the component. Look in the 09 directory after testing your movie, and you will see that the controller skin you chose has been copied to this directory. This file is also required when distributing your files. Figure 9-4. The FLVPlayback component, with full controller, playing an external FLV fileYou're not stuck with the preset controllers when using the FLVPlayback component. When you are experienced enough to create your own custom skin, you can select that file instead. That requires a bit of ActionScript, some of which you will learn in this chapter, but some that you'll have to become comfortable with on your own. However, in the meantime, you can build your own controller, piece by piece:
The first line prevents the video from playing automatically, as a change from your prior projects. The second and third lines use the playPauseButton and stopButton properties to identify the component instance names of the components that serve these purposes. Just by making this assignment, you'll enable the buttons to control your video. Think of the button components as already scripted but with nothing to control. Once you pair them with an FLVPlayback display, they will work together. |