17 Replies Latest reply on Jul 13, 2006 7:16 AM by skauty

    Controlling external flv with ActionScript

    skauty
      I'm using the NetStream Class to control the playback of an external flv. I've got a Pause/Play button using .pause, and Fast Forward and Rewind buttons using .seek. What I want to do is once the video is done playing to automatically reset back to the beginning of the video, allowing the user to press play to view the video again without having to reload the page. Right now when the video finishes, the user has to rewind the video in order to watch it again. I thought I could use .time to determine when the video reaches the end to go back to "0" in the video playhead but so far I have not been able to get this to work. Any ideas would be appreciated. Currently everything is done in frame one of the swf. Thanks.
        • 1. Re: Controlling external flv with ActionScript
          Craig Grummitt Level 3
          Use NetStream.onPlayStatus to determine when a stream is complete.
          • 2. Re: Controlling external flv with ActionScript
            skauty Level 1
            I tried using onPlayStatus but I get an error saying: There is no property with the name 'onPlayStatus'. I'm using MX 2004 and there is no mention of onPlayStatus in the help files. Is this property not available in MX 2004? Is there any other way to determine when a stream has finished playing?
            • 3. Re: Controlling external flv with ActionScript
              Rothrock Level 5
              Might want to reread those help files for the NetStream class. AFAIK, there is no onPlayStatus in Flash 8 or 7. I'm sure it doesn't take much to leap from onPlayStatus to onStatus? Really the only way to determine when a stream has finished playing is to determine when it has finished playing.
              • 4. Re: Controlling external flv with ActionScript
                skauty Level 1
                Not sure what you mean by 'the only way to determine when a stream has finished playing is to determine when it has finished playing'

                In the Flash Media Server LiveDocs it says NetStream.onPlayStatus is an Event Handler invoked when a NetStream object has completely played a stream. I don't quite know how to use this but I want to basically say:

                netStream.onPlayStatus = function(reset) {
                if (reset.code == "NetStream.Play.Complete") {
                netStream.seek(0);
                }
                };
                • 5. Re: Controlling external flv with ActionScript
                  Rothrock Level 5
                  Are you using the Flash Media Server? If so posting to the Flash Media Server forums might be more helpful.

                  But if you are using Flash 7 (MX04) then you should read the Flash MX04 help files. Where you will quickly see there is a myNetStream.onStatus event. The code you will need is almost identical to what you have there – except it will work!

                  What I meant by that comment was that the way to do it is the way to do it, there are no others.
                  • 6. Re: Controlling external flv with ActionScript
                    Craig Grummitt Level 3
                    NetStream.Play.Complete is handled by onPlayStatus and not onStatus. see livedocs for more information on onPlayStatus. According to Flash Media Server documentation, it is available from Flash Player 6. However, I just had a look at Flash Communication Server livedocs and there doesn't seem to be an onPlayStatus in its documentation. One of the manuals must be wrong - which one, I don't know... I noticed that NetStream.Play.Complete isn't mentioned in the NetStream information objects in the FCS livedocs either, so it looks like either the feature isn't documented or its unavailable, and by the sound of the error you got: "There is no property with the name 'onPlayStatus'." it sounds as though its unavailable...

                    what was the problem you were having with testing the time versus the duration of the video?
                    • 7. Re: Controlling external flv with ActionScript
                      skauty Level 1
                      The problem I'm having is in referencing when a stream is complete so upon finishing, the flv will go back to "frame 0" so the user can press play to view the video again without having to reload the page. Someone in the FMS forum suggested using onMetaData to determine and reference the lasttimestamp and "reset" the video, but I haven't tried that to see if it works yet. Any suggestions are greatly appreciated
                      • 8. Controlling external flv with ActionScript
                        Craig Grummitt Level 3
                        yes i understand what you want to happen. i was referring to your initial post where you said you tried to "use .time to determine when the video reaches the end" but had "not been able to get this to work". I was more asking what was the problem you had with this technique? and specifically, whether you have a way of determining the duration of an flv in FCS as i noticed that onMetaData(the event handler used to determine duration in FMS) also does not appear to be in the documentation for FCS.
                        • 9. Re: Controlling external flv with ActionScript
                          Rothrock Level 5
                          Well according to my documentation for Flash 7 and 8 as well as testing it in Flash 7, NetStream.Play.Complete is handled by onStatus. Have you tried it? Is there a reason you seem to refuse to want to make something that works?

                          Under Flash 7 the onMetaData is undocumented but it does work – kinda. If you strict type your NetStream you will get a message that onMetaData doesn't exist when you try and compile. But if you don't strict type it works just fine.

                          If you are really using Flash MX04 pro then you really should take my advice. If you are using something else, please say so and I will stop wasting my time!
                          • 10. Re: Controlling external flv with ActionScript
                            Craig Grummitt Level 3
                            i don't think any of us are refusing to make something that works, Rothrock. We're just trying to get to the bottom of a problem...

                            the link i provided earlier in livedocs describes the information objects that onPlayStatus receives - these include NetStream.Play.Switch and NetStream.Play.Complete. These livedocs describe the information objects that onStatus receives. They do not include NetStream.Play.Complete. In practice I find that this corresponds to the information objects onStatus and onPlayStatus receive when building video streaming applications. However, I am using Flash 8 and FMS, whereas skauty is using Flash MX 2004, so I can only speculate on solutions and can't actually replicate the problem. (Rothrock, where is the documentation that you say describes onStatus as receiving NetStream.Play.Complete?)

                            If as you say you can get onMetaData to work, couldn't this also apply to onPlayStatus?
                            • 11. Re: Controlling external flv with ActionScript
                              Rothrock Level 5
                              I think obviously there is a difference between FMS and Flash MX04. The documents I refer to are built into the help menu in Flash 7 and 8 both include the onStatus event and absolutely no onPlayStatus event.

                              I made a mistake. I meant NetStream.Play.Stop – which was very poorly named. That is what onStatus will return when it reaches the end. It isn't really "stop" it is "complete." So I tend to read it as such!

                              AFAIK, onPlayStatus doesn't work. I just tried it and just nothing works. My guess is that when they took the bits from FMS into Flash MX04 they didn't do a very good job. They purposefully renamed onPlayStatus to onStatus – with a limited variety of events returned (What is Switch?) and they forgot to explicitly include onMetaData, but didn't remove it either. I do also recall that in the beginning there were problems with the FLV exporter properly including the meta data with the FLV. So perhaps they had planned on including onMetaData but at the last minute unexposed it since it would too blatantly show up a flaw with the main reason to get MX04. Who knows?

                              Some really good tutorials on building a video system using NetStream under Flash 7 can be found at gotoAndLearn.com. They may have been updated to Flash 8 since.

                              PS: If you just can't give up strict typing (ughh) there is a workaround on that site that can let onMetaData work in that instance as well.
                              • 12. Controlling external flv with ActionScript
                                Craig Grummitt Level 3
                                >>I think obviously there is a difference between FMS and Flash MX04. The documents I
                                >>refer to are built into the help menu in Flash 7 and 8 both include the onStatus event
                                >>and absolutely no onPlayStatus event.

                                Yeah you're right onPlayStatus isn't in the NetStream class Flash documentation as this is more about using this class for progressive download, whereas the documentation i linked to referred to the NetStream class used in FMS Client-side scripting for streaming video.

                                >>I made a mistake. I meant NetStream.Play.Stop – which was very poorly named. That
                                >>is what onStatus will return when it reaches the end. It isn't really "stop" it is "complete."
                                >>So I tend to read it as such!

                                NetStream.Play.Stop does seem to be very similar to NetStream.Play.Complete in progressive downloads. however i know you can't guarantee that NetStream.Play.Stop occurs at the same time as NetStream.Play.Complete in a streaming video through FMS, as a NetStream.Play.Stop can occur for reasons other than completion.

                                >>...My guess is that when they took the bits from FMS into Flash MX04 they didn't do a
                                >>very good job. They purposefully renamed onPlayStatus to onStatus...

                                onStatus does still exist in FMS Client side scripting...

                                >> – with a limited variety of events returned (What is Switch?)

                                switch refers to playlists - only relevant to FMS streams.

                                Anyway, it appears as though all of this talk of the FMS is moot regarding the original poster, as I've just had a look at skauty's posts in the Flash Media Server forums, ironically, and discovered that skauty is using progressive download and not FMS... Simple but important distinction...
                                • 13. Re: Controlling external flv with ActionScript
                                  Rothrock Level 5
                                  Interesting about NetStream.Play.Stop. I haven't tested it exhaustively, but under Flash MX04 I haven't found anyway to make it happen other than complete. We have had some debates about it here on the forums and nobody else had found it to occur at any other time either.

                                  Do you have any reproducible examples that work in MX04?
                                  • 14. Re: Controlling external flv with ActionScript
                                    skauty Level 1
                                    I appreciate all the feed back and I must say I've learned alot just reading the posts. I didn't originally realize that .onPlayStatus was only available in FMS (thus my posts in the FMS forum). NetStream.Play.Complete didn't work with .onStatus but I will try NetStream.Play.Stop and let you know if it works. Thanks.
                                    • 15. Re: Controlling external flv with ActionScript
                                      Craig Grummitt Level 3
                                      Rothrock - I'm working in Flash 8 with FMS2, so I can only speculate about what works in MX04. However in Flash 8 with FMS2, I definitely get NetStream.Play.Stop events when I close a NetStream. I thought I may have also received this event when seeking as well, but my FMS isn't up for testing right now to test that out.

                                      • 16. Re: Controlling external flv with ActionScript
                                        skauty Level 1
                                        Interesting - NetStream.Play.Stop works but, a trace indicates two stop actions at the beginning of the stream before the video even starts and that's it for the rest of the stream. Of course running NetStream.seek(0) if NetStream.Play.Stop will result in the playhead going back to "0" before the video starts. Any ideas why I would be getting stops at the beginning and not at the end>
                                        • 17. Re: Controlling external flv with ActionScript
                                          skauty Level 1
                                          Actually there are two more stops indicated in the ouput box about 20 seconds after the video appears to have ended.