Flash CS5 AS2.0 pause netstream video
I'm using basic AS2 for something and was wondering where i'm going wrong? Please help.
Here's the code:
The video loads, and plays, and pauses at 5 seconds as meant to. It also shows the button which is, until the point hidden. But the button doesn't un-pause.
The funny thing is, the button does pause and un-pause if you use it anytime before the loop has implemented the stop.
One thing I noticed above is that you have two checkTime functions and I'm not sure why.
I would put a trace on the button that refers to the netstream:
Hit the button before the video pauses automatically (which you said is working) and note the message. It should say something like object[NetStream]. Then after the video pauses, hit the button and see what message you get. If it's the same message you got before, then it's a problem with the pause command. If you don't get a message, you probably have a keyframe that is clearing out your button action before the video automatically pauses (your button action no longer exists). If the trace shows an error, you know that the button cannot see the netstream (scope) which is why it can't pause it.
That first checkTime displays the playbar time of the flv as it's playing. I was using it to make sure that i was pausing where i was telling it to. If you completely remove that code it doesn't affect the functionality second checkTime.
I'll try what you've suggested and let you know what i find.
I'm not a code expect so i wouldn't know where to begin troubleshooting this, but i feel like the function statement locks the flv at 5 seconds once it's paused because it's a loop that's checking continuously. So even a button that's telling it to unpause, the code is overiding it. I didn't spend too much testing my theory but i did a netStream.seek(6); so that it forced the flv just out of the range where the function is true and it seemed to work.
Any idea how we could set the function to stop working once it's paused?
Update your code to store the setInterval as a variable. This allows you to clear it after you hit 5 seconds and pause your video. Then to start monitoring your netstream playback again after pressing your button (maybe to stop it at 10 seconds) you will need to call another setInterval statement.
It worked... well done. Now i can sleep tonight. Incase you want to see the file working, here's the link http://www.vibrant-sorcery.com/flash_test/test.swf
The button in the bottom middle only appears at 5 seconds when the video pauses. When you click it resumes and the button hides until 10 seconds when it pauses again. Thanks Sam!
This is the code i ended up using:
Awesome! Now, if you wanted to get fancy, instead of hiding your button you should disable it by default, enable it when you pause your video, then disable it again when you start playing again. That way you won't get the hand when you find it accidentally while it's hidden.
Indeed that would be nice but that is a task for another day. For now, i'm going to enjoy this little victory.
Now i can create a 2 minute animation in After Effect with 20 key slides that blend into each other. Then i can play it through Flash with pauses so that it appears to work like a timed presentation, but with the power of having all the video effects. Doing the movement of elements in flash is not only very time consuming it's also very limited.
Thanks again Sam!
Remember me? Hope all is well. Was hoping you could take this one step further and help me to get more control over this code.
The below is working, but i'm limited by having to stop the playing video at with 1 second sharp, or 2 seconds sharp. It would be great if it could stop it at 1.5 seconds (for example) or even better. If i could stop it by frame... for example first stop is at frame 22 and then 2nd stop is at frame 45 etc.
Hope you can help!
Well, you have two options. The reason that the video can only be stopped per second is because we're rounding down the playback head. So no matter if it's 2.01 or 2.99 seconds, the code is seeing it as 2 because we are running it through Math.floor(). If instead you want to check for a spot specific to the hundredths, you would need to update the code to:
The other option is to import your video directly to the timeline and scratch all of this code. It converts the movie into still frames that fill up your timeline. You can then simply put "stop();" on the frames you want it to stop at. I've used this method for simple videos, but it can get ugly very quickly. You'll also probably need control the audio separately.
Amazing - thanks for your quick reply! Appreciate it.
I actually found that seeking method to be a little sketchy - i guess it's just the way Flash handles netstream videos. Random previews of the flash file will result in certain points being missed and other times not. I'm guessing due to the period as you suggested but as i make the number smaller i feel like it's putting strain on the presentation.. it becomes jerky.
As you suggested i've placed the flv on the timeline (in a movieclip) which has given me much better control of the video. This is not really ideal because the ultimate goal is to keep the many videos that the presentation references in an external folder - that allows me to update the videos if required without touching the code. Nevertheless, it does work so i'm grateful.
Do you know if the method of video on the timeline (in a movieclip) is known for being specifically buggy? The reason i ask is because it looks great now but when doing the actual presentation i'd hate the flash file to crash.
Thanks a lot
Not sure if there are issues with it crashing. Rather, I've had some issues with the playback not being true to time (getting a little ahead, then a little behind) during playback. Also, once you have the video on the timeline, you cannot change the frame rate of your project. If you do, you'll have to reimport the video.
If you did want to keep the files external, you could do a hybrid approach. Create a blank project and load your video to a timeline. Add in any hard stops on frames if you like. Then export that project as a swf. Then in your main project, you can load that swf in as a native movieclip. It will give you full control over the timeline and playback, while keeping your main project small and nimble. Here is how that looks:
Anyway, it's an option if you want a reusable platform that you can keep small and nimble.
Excellent, thanks again Sam!