Using the onStatus event handler to detect the end of the FLV playback and then loop

onStatus is a method of the NetStream class. To check for the end of FLV playback, we can override it. You can view the implementation of this method by examining the onStatus function on frame 1 of the main timeline of the sample movie.

myStream.onStatus = function(info){
trace("info="+info.code);
if (info.code == "NetStream.Play.Stop"){
// Set flag, we will need to wait for
// "NetStream.Buffer.Empty" before
// actually restarting the movie.
stopped=true;
}
if (info.code == "NetStream.Buffer.Empty"){
// At this point, the movie has stopped, and
// the buffer is empty.
// We're ready to restart the movie.
if (stopped){
myStream.seek(0)
myStream.play(videoUrl);
stopped=false;
}}}
Here we need to check if the event being sent is NetStream.Play.Stop. When you receive NetStream.Play.Stop, it means that the movie has stopped playing. Note however, because Flv playback has a tendency to freeze when you start a movie without waiting for the playback buffer to be empty, we should wait for the NetStream.Buffer.Empty event as well. When both conditions are met, then we’re ready to replay the movie.
Second Example:
private function onStatus(object) {
if (object.code == "NetStream.Play.Start") {
// this is invoked when the stream starts playing
trace("play");
} else if(object.code == "NetStream.Buffer.Full") {
// this is invoked when the stream is buffered
trace("full");
} else if(object.code == "NetStream.Play.Stop") {
// rewind and pause on when movie is finished
trace("done");
_ns.seek(0);
_ns.pause();
_timeline.playBut._visible = true;
_timeline.pauseBut._visible = false;
if( _mediaType == "audio" ){
_timeline.eq_mc.gotoAndStop(1);
}}};

Nhận xét

Bài đăng phổ biến từ blog này

Ký tự viết tắt trong chat & email

dung lượng RAM lớn nhất mà HĐH cấu trúc 32-bit nhận được

Ubuntu LAMP Server