4 Replies Latest reply on Nov 16, 2010 2:04 PM by everythingelsewastakentoo

    having trouble removing traits from a media element

    everythingelsewastakentoo

      I am having difficulty removing a trait from a subclass of the LightweightVideoElement.  Depending on the type of video playing through the netstream, I want to remove the seek trait to prevent seeking with the chrome scrub bar.

       

      My problem is that when I remove the trait from the element the hasTrait method is still returning true.  To demonstrate I add a listener in my element's constructor like so:

       

      addEventListener(MediaElementEvent.TRAIT_REMOVE,announceTraitRemoved);

       

      And my function is:

      private function announceTraitRemoved(e:MediaElementEvent):void
      {
                  trace("Element --> announceTraitRemoved --> TRAIT REMOVED: "+e.traitType + " so hasTrait: "+hasTrait(e.traitType));

      }

       

      The output of the function after calling removeTrait(MediaTraitType.SEEK) is:

      Element --> announceTraitRemoved --> TRAIT REMOVED: seek so hasTrait: true

       

      It never returns hasTrait: false for the seek trait.

       

      This is problematic because the chrome package ScrubBar determines if the scrubber is enabled by listening to this event in a similar fashion and using the hasTrait method, so I cannot figure out how to disable the scrub bar.

       

      What am I doing wrong?  If it matters, I am using 1.0gm.

       

      Thanks.

        • 1. Re: having trouble removing traits from a media element
          bringrags Level 4

          The traitRemove event is fired just prior to the trait being removed, so that clients can inspect the to-be-removed trait and see what's going to disappear.  That's why hasTrait returns true.

           

          Note that a better approach might be to wrap the LightweightVideoElement in a custom ProxyElement which blocks the SeekTrait.  This way, you wouldn't need to worry about re-adding the SeekTrait when you want to re-enable seeking, you would just unblock the SeekTrait.  The ExamplePlayer sample app has an example showing how to use a ProxyElement to prevent seeking.

          1 person found this helpful
          • 2. Re: having trouble removing traits from a media element
            everythingelsewastakentoo Level 1

            Okay that makes sense.  I didn't realize the event was fired ahead of time because some of the traits were returning false for the function... but I guess it just happened to be a timing thing from being removed and added and such.

             

            For this case, the custom netstream "knows" if seeking is possible and skips the actual seeking part of the seek call and only dispatches events if seeking is not allowed, so I am not actually worried about the SeekTrait exactly.  I want to convey to the user that the video cannot be seeked through by "greying" out the scrubber.

             

            From what I understand the proxy element would just stop the seek event from hitting the netstream and would not trigger the ScrubBar to grey out the scrubber.

             

            How does one signal to the ScrubBar that the scrubber should be disabled?  This is the check that the chrome package ScrubBar uses when traits are added or removed:

            scrubber.enabled = media ? media.hasTrait(MediaTraitType.SEEK) : false;

             

            Do I have to remove the seek trait and then toggle another trait?

            • 3. Re: having trouble removing traits from a media element
              bringrags Level 4

              The ScrubBar should be grayed out if the SeekTrait is not present (i.e. hasTrait == false).  If you use the proxy approach that I described, it should work the way you want.

              • 4. Re: having trouble removing traits from a media element
                everythingelsewastakentoo Level 1

                Thanks Brian.  I read more about the ProxyElement and appreciate the help.