1 person found this helpful
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.
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?
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.
Thanks Brian. I read more about the ProxyElement and appreciate the help.