« Home « Kết quả tìm kiếm

Loading and Controlling External Video


Tóm tắt Xem thử

- Not only does Flash MX 2004 not need Flash Communication Server when using external video, but it provides some excellent tools in the form of Media components.
- The clip can be edited separately from the SWFs that use it..
- The clip can be progressively downloaded as it plays, making it unnecessary for the entire clip to load before it can be viewed..
- To use an external video clip in a Flash project, it must first be converted to the .flv (Flash Video) file format.
- Flash has the built-in capability to import most video formats (including AVI and QuickTime), which can then be exported to the FLV format for use as an externally loaded clip.
- The direct way is by creating an instance of the Video class and then loading video into that object via instances of the NetConnection and NetStream classes.
- These components allow you to work with the Media class to handle the most demanding video-related tasks, including the use of cue points..
- The Media components come in three forms:.
- Graphical playback controls are not provided with this component, but the loaded file can be controlled using methods of the component, including play() and stop.
- Associating an instance of the MediaController component (named controller) with an instance of MediaDisplay component (named display) is as simple as this:.
- component instances, there are a number of properties, methods, and events that can be used to configure and control Media component instances via ActionScript.
- All these components inherit functionality from the Media class, which means that instances of the components can be controlled and configured using common commands.
- One of the most important tasks a Media component instance can perform is to load media.
- This can be done using the setMedia() method:.
- This line loads myVideo.flv into the Media component instance named.
- Because Media components can also load MP3 files, the second parameter of the setMedia() method is used to define the media type.
- Media cannot be loaded into instances of the MediaController component..
- After media has been loaded into an instance, its playback can be controlled via ActionScript using the play.
- Here's an example of the play() method:.
- Media component instances generate various events, allowing your application to react to such actions as a click of the Play button, the end of playback, or a volume adjustment by the user.
- myMediaComponent.addEventListener("volume", myListener);.
- Here, myListener is set up to react to volume changes in the myMediaComponent instance..
- Media component instances can generate unique events in response to cue points.
- Cue points are used to mark points of time during a media file's playback.
- When playback reaches a point in time marked as a cue point, the component instance playing the media fires a cuePoint event.
- This event can be captured by a Listener, which can be scripted to react to that particular cue point.
- myMediaComponent.addEventListener("cuePoint", myListener);.
- This script adds a cue point named liftoff to the myMediaComponent instance.
- This cue point is fired 54 seconds into the playback of the loaded media.
- The Event object sent to the cuePoint event handler when the event is fired contains the name of the cue point ("liftoff") so that the event handler can be scripted to take action based on that specific cue point's being reached..
- In this exercise, you'll use an instance of the MediaPlayback component to load and play an external video file.
- You'll add cue points so that the application can react to specific points during the video's playback..
- Open video1.fla in the Lesson18/Assets folder..
- Our application will eventually load a JPG into the cueBox_mc instance in response to a specific cue point's being reached.
- The cue_txt text field will display text associated with that loaded JPG..
- The Media Component layer holds an instance of the MediaPlayback component named display.
- Using your operating system's directory-exploring application, navigate to the Lesson18/Assets directory and locate bluezone.flv, cue0.jpg, cue1.jpg, cue2.jpg, cue3.jpg, cue4.jpg, cue5.jpg and cue6.jpg..
- The other files represent snapshots of various points in the video file's playback..
- Our application will eventually load each of these snapshots, using cue point functionality..
- He brilliantly wrote, produced, and directed this commercial, which Derek feels is one of the best he's ever seen.
- With the Actions panel open, select Frame 1 of the Actions layer and add the following script:.
- display.autoPlay = true;.
- display.activePlayControl = true;.
- display.controllerPolicy = "on";.
- display.totalTime = 60;.
- The first line tells the instance to immediately begin playback of the loaded media file.
- The next line tells the instance to show the Play button in an active state, indicating that the media file is playing.
- The last line indicates to the component instance that the media to be loaded is 60 seconds long.
- accurately reflect the playback progress of the loaded file.
- The totalTime property doesn't need to be set in order for the rest of the functionalities of the component instance to work properly..
- Before we script the display instance to load the video file, let's set it up to open a URL when playback of the loaded file is complete..
- Add the following script:.
- display.addEventListener("complete", displayListener);.
- Here we've created the displayListener object and scripted it to open a URL in response to the firing of a complete event.
- display.setMedia("bluezone.flv FLV");.
- This loads bluezone.flv into the display instance..
- You can interact with any of the playback controls to see the effect they have on the video's playback.
- Let's return to the authoring environment to add several cue points..
- With the Actions panel open, select Frame 1 of the Actions layer and insert the following script, just below the line.
- display.addEventListener("complete", displayListener);:.
- display.addCuePoint .
- This script creates seven cue points in the display instance.
- The first cue point is named "0".
- and is set to trigger one second into the media's playback.
- The next cue point is named "1".
- and is set to trigger eight seconds into the media's playback..
- The remaining cue points are self-explanatory.
- The name of the cue points can be any string value you choose.
- If you load a different media file into the display instance, these cue points still exist.
- Because these cue points may not be appropriate for the newly loaded file, you can use the removeAllCuePoints() method to delete them all quickly:.
- display.removeAllCuePoints().
- Insert the following script just below display.addCuePoint .
- Each of these snippets is displayed in the cue_txt text field when its corresponding cue point has been reached.
- It should be noted that the index position of each snippet relates to the name of a cue point added in the preceding step (the cue point named "0".
- relates to the snippet in index position 0 of this array)..
- Insert the following script just below the closing brace of the displayListener.complete event handler:.
- index + ".jpg cueBox_mc");.
- display.addEventListener("cuePoint", displayListener);.
- The first part of this script creates a cuePoint event handler on the displayListener object, and the last line of the script registers that object to listen for that event from the display instance.
- Because we added seven cue points to the display instance in Step 7, this event handler will be triggered seven times by the time the video has played through.
- Let's look at how the event handler works..
- The event handler is passed an Event object when the event is fired.
- This Event object contains the name and time of the cue point that fired the event.
- The name of the cue point is accessible using this syntax:.
- and the time of the cue point with the following syntax:.
- When our third cue point is fired, the event objects will have the following values:.
- All we're really interested in is the name property of the cue point that triggered the event.
- The first line within the event handler converts this value to a number and assigns it to the index variable.
- The remaining two lines in the event handler use this value.
- A loadMovie() action loads one of the external JPG images into the cueBox_mc instance.
- When the first cue point is reached, cue0.jpg is loaded.
- when the next cue point is reached, cue1.jpg is loaded.
- The last line in the event handler displays one of the text snippets in the.
- cueTextArray in the cue_txt instance.
- When the cue point named "0".
- is fired, cue0.jpg is loaded and the text snippet at index position 0 of the cueTextArray is displayed.
- when the cue point named .
- is fired, cue1.jpg is loaded and the text snippet at index position 1 of the.
- When the movie appears and the video begins to play, simply sit and watch as cue points are reached and the cuePoint event handler does its job.
- Utilizing this event is a great way to synchronize other elements in your movie to the playback of a video, or even an MP3 file.

Xem thử không khả dụng, vui lòng xem tại trang nguồn
hoặc xem Tóm tắt