Start and Stop the Current Video
Start and Stop the Current Video
Included in the basic set of behaviors is the ability to play, pause, and stop the currently playing video. Note that these controls can actually be accessed through the FLVPlayback custom UI components included in Flash Professional 8. The custom UI components are simple to use, but I am including these behaviors to complete the set and offer an easy way to add the functional code to objects that are not predefined components.
I discuss these behaviors in this section:
- Toggle Play and Pause
- Stop and Reset
Toggle Play and Pause
To use the Toggle Play and Pause behavior:
- Add an FLVPlayback component to the Stage and give it an instance name in the Property inspector. Assign an FLV file path to the component’s contentPath parameter in the Component inspector.
- Add a button to the Stage and select it.
-
Open the Behaviors panel and click the plus (+) icon to access the list of behavior categories. Select the FLVPlayback Controls category and choose Toggle Play and Pause from the list. The behavior’s dialog box opens (see Figure 4).
Figure 4. Toggle Play and Pause dialog box showing the FLVPlayback instance selected in the target list
- Browse for the FLVPlayback instance in the target list in the bottom portion of the dialog box. This targets the instance name of the component displaying the video. A best practice is to use the Relative option for the path, as shown in Figure 4. If you have problems adding paths to component buttons, try using the Absolute option instead.
- Click OK.
Here’s the code that is added to the button:
// Start Toggle Play/Pause Behavior
var m = this.myVideo;
if(!m.playing)
{
if(Math.round(m.playheadTime) == m.totalTime)
m.stop();
m.play();
}else{
m.pause();
}
// End Toggle Play/Pause Behavior
Stop and Reset
To use the Stop and Reset behavior:
- Add another button to the Stage and select it.
-
Open the Behaviors panel and click the plus (+) icon to access the list of behavior categories. Select the FLVPlayback Controls category and choose Stop and Reset from the list. The behavior’s dialog box opens (see Figure 5).
Figure 5. Stop and Reset dialog box showing that the video is set to rewind to the start after it stops
- Select the Rewind to Start check box if you want the video to reset to the beginning after it stops.
- Browse for the FLVPlayback instance in the target list in the bottom portion of the dialog box. This targets the instance name of the component displaying the video. A best practice is to use the Relative option for the path, as shown in Figure 5. If you have problems adding paths to component buttons, try using the Absolute option instead.
- Click OK.
Here’s the code that is added to the button:
// Stop and Reset Behavior
this.myVideo.autoRewind = false;
this.myVideo.stop();
// End Stop and Reset Behavior
Comments