Using metadata to detect end of the movie and then loop
Beginning with FLV version 1.1, Macromedia has added a metadata section into a FLV file. The metadata contains the duration of the FLV, among other things. We can use the duration information to check whether a movie has reached the end of playback. Note that not all FLV files have metadata (you will need to use software that supports metadata to create the FLV).
We can retrieve the duration information by using the following code (frame 1 of the main timeline of the sample movie):
myStream.onMetaData = function(obj)
{
myStreamDuration=obj.duration;
trace("metadata duration="+myStreamDuration);
}
If the FLV has metadata, the code snippet above will show the duration of the FLV. You can use the Flix Pro 4 FLV to SWF Converter to check for the presence of metadata – if the FLV has no metadata, Flix will show: “[Flv has no metadata]”.
If your FLV does not have metadata information, it is recommended that you re-encode the FLV with programs that supports metadata, such as Flix Pro or the Flix Exporter.
Checking for the end of the playback using metadata is quite straightforward. Just add a loop to check if the current playback time is equal to or greater than the duration. You can view the implementation of this method by examining the code on the frame 2 and 3 of the main timeline of the sample movie.
var maxIdle=5;
if (myStreamDuration>0){
myDelta=myStream.time-myStreamDuration;
if (myDelta<0)myDelta=-myDelta;
if (myDelta<2){
if (myDelta==lastDelta){
noStreamMovement++;
}else{
lastDelta=myDelta;
noStreamMovement=0;
}
if (noStreamMovement>maxIdle){
trace("loop");
myStream.seek(0);
myStream.play(videoUrl);
lastDelta=0;
noStreamMovement=0;}
}}}
We can retrieve the duration information by using the following code (frame 1 of the main timeline of the sample movie):
myStream.onMetaData = function(obj)
{
myStreamDuration=obj.duration;
trace("metadata duration="+myStreamDuration);
}
If the FLV has metadata, the code snippet above will show the duration of the FLV. You can use the Flix Pro 4 FLV to SWF Converter to check for the presence of metadata – if the FLV has no metadata, Flix will show: “[Flv has no metadata]”.
If your FLV does not have metadata information, it is recommended that you re-encode the FLV with programs that supports metadata, such as Flix Pro or the Flix Exporter.
Checking for the end of the playback using metadata is quite straightforward. Just add a loop to check if the current playback time is equal to or greater than the duration. You can view the implementation of this method by examining the code on the frame 2 and 3 of the main timeline of the sample movie.
var maxIdle=5;
if (myStreamDuration>0){
myDelta=myStream.time-myStreamDuration;
if (myDelta<0)myDelta=-myDelta;
if (myDelta<2){
if (myDelta==lastDelta){
noStreamMovement++;
}else{
lastDelta=myDelta;
noStreamMovement=0;
}
if (noStreamMovement>maxIdle){
trace("loop");
myStream.seek(0);
myStream.play(videoUrl);
lastDelta=0;
noStreamMovement=0;}
}}}
Nhận xét
Đăng nhận xét