4 Replies Latest reply on Nov 8, 2010 3:24 PM by MonsieurWeile

    Abort video loading - is it possible?

    MonsieurWeile

      Hello all.

       

      I've made a web-player, based on OSMF. Initially, it loads a video in standard quality - but the user can then choose to view a larger version of the video, using a "switch resolution"-button.

      The problem is that, when switching, the player continues the low-res clip - and vice versa. As you can see in the code, I've tried different approaches to solve this issue.


      So: I need to force the movie to stop loading - and preferably without forcing the player to load itself. Is that possible?

       

       

      Here's the code that loads the video:

       

      public function loadVideo(theURL) {
                  trace("Load video "+theURL);
                  if (mediaContainer) {
                      mediaPlayer.stop();
                      videoplaceholder.removeChild(mediaContainer);
                      mediaContainer.removeMediaElement(currentMediaElement);
                      //mediaFactory.removeItem(mediaElement);
                      //mediaPlayer.media = undefined;
                  }       
                 
                  mediaPlayer = new MediaPlayer();
                  // Når view'et bliver tilgængeligt, send da en event
                  mediaPlayer.addEventListener(MediaPlayerCapabilityChangeEvent.CAN_PLAY_CHANGE, onViewable);
                  mediaElement = mediaFactory.createMediaElement(new URLResource(theURL));
                 
                  layout = new LayoutMetadata();
                  layout.width = playerdimensions[0];
                  layout.height = playerdimensions[1];

       

                  if (! scrubber) {
                      addScrubberAndStuff();
                  }

       

                  mediaPlayer.addEventListener(DisplayObjectEvent.MEDIA_SIZE_CHANGE, onDimensionsChange);
                  mediaPlayer.addEventListener(TimeEvent.CURRENT_TIME_CHANGE, onCurrentTimeChange);
                  mediaPlayer.addEventListener( TimeEvent.COMPLETE, videoHasEnded );
                  mediaPlayer.media = mediaElement;

       

              }

       

      Best regards,

      Anders

        • 1. Re: Abort video loading - is it possible?
          bringrags Level 4

          How are you doing the switch from the low-res video to the high-res video?  Typically, when you assign a new MediaElement to the MediaPlayer's media property, it will force an unload of the current MediaElement first.  So it's not clear to me why you would end up with the low-res video still playing.  Unless you're using two MediaPlayer instances?

          • 2. Re: Abort video loading - is it possible?
            MonsieurWeile Level 1

            Hello again - and thank you for your comment.

             

             

            Just to make the structure clear; I have a setup that looks like this:


            [EBplayer class] -> [OnDemand class] -> Scrubber (MovieClip and has a class attached to it and also contains a button (mc) that has a class called ChangeSize attached to it.

             

             

            Here's the ChangeSize class which extends the OnDemand class:

             

                    private function changeSizeNow(event:MouseEvent) {
                        if (isNormal) {
                            goLarge();
                        } else {
                            goStandard();
                        }
                    }
                   
                    private function goLarge() {
                        // read movie @large
                        MovieClip(this.parent.parent.parent.parent).autoplay = true;
                        MovieClip(this.parent.parent.parent.parent).loadVideo(htmlDecode(MovieClip(this.parent.pa rent.parent.parent).directXML.@large));
                        ExternalInterface.call("resize(true)");
                        //ExternalInterface.call("setFlashWidth('flashid', 960)");
                        //ExternalInterface.call("setFlashHeight('flashid', 540)");
                        isNormal = false;
                        this.gotoAndStop(2); // This is the button icon     
                    }
                   
                    private function goStandard() {
                        MovieClip(this.parent.parent.parent.parent).autoplay = true;
                        MovieClip(this.parent.parent.parent.parent).loadVideo(htmlDecode(MovieClip(this.parent.pa rent.parent.parent).directXML.@normal));
                        ExternalInterface.call("resize(false)");
                        //ExternalInterface.call("setFlashWidth('flashid', 614)");
                        //ExternalInterface.call("setFlashHeight('flashid', 345)");
                        isNormal = true;
                        this.gotoAndStop(1);
                    }

             

            ...and the loadVideo method lies, as mentioned earlier, in the OnDemand-class.

             

            Here, you can see what Charles is seeing when I press the button that changes size:

            charles.gif

            • 3. Re: Abort video loading - is it possible?
              bringrags Level 4

              Ok, it looks like you'll create a second instance of MediaPlayer the second time loadVideo() gets called.  I would recommend using one instance of MediaPlayer no matter how many different videos get loaded.  The loadVideo() method should only create the appropriate MediaElement and assign it to MediaPlayer (as well as add it to MediaContainer).

              • 4. Re: Abort video loading - is it possible?
                MonsieurWeile Level 1

                I'll put a statue of you on my living room floor

                I should have seen the solution myself - what else to say than D'OH

                 

                Thanks, Mister.