Yes it's bizarre that there isn't an out-of-box solution for this. I came
across the same problem a while ago. The solution I came across was to check
if the play head is not moving while the movie is supposed to be still
playing (that is, not paused or stopped).
For this you need to set a "lastCheck" property, which needs to be set to 0
every time you start a movie (but not from paused), or manually stop it, and
while the movie is playing, you need to keep checking it using an interval
or enterFrame event.
The function you need is this:
public function checkStatus(){
//_global.tt("checkStatus", movie_flv.playing,
movie_flv.playheadTime, lastCheck)
if (play_btn.selected && movie_flv.playheadTime &&
movie_flv.playheadTime == lastCheck){
stopMovie()
}else{
lastCheck = movie_flv.playheadTime;
}
}
To set the function into context, I pasted the entire class below.
It worked like a charm, but my class is using custom buttons and commands to
play the movie. I'm not sure how I'd integrate it with Adobe controller
components. For example, you might need to devise a different check instead
of play_btn.selected.
Karina
Here's the full class code:
-----------------------------
import com.neoarchaic.ui.*;
class com.neoarchaic.projects.macbeth.section.view.elements.VideoBox extends
AbstractComponent {
private var title_txt:TextField;
private var play_btn:ToggleButton;
private var stop_btn:AbstractButton;
private var movie_flv:mx.controls.MediaDisplay;
private var url:String;
private var link:Object;
[Inspectable( type="String", defaultValue="")]
public var id:String
private var t:Number
private var lastCheck:Number
public function initSection () {
//_global.tt("initSection - videobox")
play_btn.addEventListener("click", this, "toggleMovie")
stop_btn.addEventListener("click", this, "stopMovie")
var movieData = broadcastMessage("getVideoBox", id);
//_global.tt("video", id, movieData)
setMovie(movieData, false)
lastCheck = 0;
}
public function setMovie(movieData:Object, autoPlay:Boolean,
mc:String){
if (mc != undefined && mc != id){
return;
}
clearInterval(t)
var oldUrl:String = url
url = movieData.url.data;
if (url == undefined && movieData.title.data == undefined){
this._visible = false;
return;
}
this._visible = true;
link = movieData.link;
title_txt.text = movieData.title.data != undefined ?
movieData.title.data : "";
if (url != oldUrl){
movie_flv.setMedia(url)
}
if (autoPlay){
movie_flv.stop()
play_btn.selected = true;
toggleMovie(null, true)
}else{
play_btn.selected = false;
movie_flv.stop()
}
}
public function toggleMovie(e:Object, selected:Boolean){
//_global.tt("toggleMovie", selected)
clearInterval(t)
if (selected){
movie_flv.play()
lastCheck = 0;
t = setInterval(this, "checkStatus", 2000)
} else {
movie_flv.pause()
}
}
public function stopMovie(e:Object, noTrigger:Boolean){
//_global.tt("stopMovie")
clearInterval(t)
play_btn.selected = false;
movie_flv.stop()
lastCheck = 0;
if (!noTrigger && movie_flv.playheadTime){
broadcastMessage("selectLink", link)
}
}
public function checkStatus(){
//_global.tt("checkStatus", movie_flv.playing,
movie_flv.playheadTime, lastCheck)
if (play_btn.selected && movie_flv.playheadTime &&
movie_flv.playheadTime == lastCheck){
stopMovie()
}else{
lastCheck = movie_flv.playheadTime;
}
}
}
> -----Original Message-----
> From: Andreas R [mailto:[EMAIL PROTECTED]
> Sent: 06 September 2006 14:57
> To: Flashcoders mailing list
> Subject: [Flashcoders] Reliable local FLV stop event
>
> I know this is an old question but i can't really seem to get
> a good grasp of it.
>
> I have a client that loads FLVs locally off the machine it
> runs on. When movies stop, events get broadcasted. however
> sometimes the stop event i set up fails:
>
> onStatus = function(info){
> switch(info.code){
> case "NetStream.Play.Start":
> stopped = false;
> break;
> case "NetStream.Buffer.Empty":
> if(stopped){
> broadcastMessage("onVideoComplete");
> }
> break;
> case "NetStream.Play.Stop":
> stopped = true;
> break;
> }
> }
>
> On tracing out info.code onStatus, i see that buffer.empty
> and buffer.full flicker on and off during playback, and that
> gets me worried. Sometimes Play.stop is called before the
> buffer has played out, but buffer.flush and buffer.empty
> right now seem so unreliable in terms of actually firing at
> the end of the FLV that i'm confused as to how to even approach this.
>
> Anyone got a solid, sound solution?
>
> Thanks,
>
> - Andreas SJ
>
> _______________________________________________
> [email protected]
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com http://training.figleaf.com
>
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com