6 Replies Latest reply on Mar 10, 2010 9:10 AM by bringrags

    Strange bug (ArgumentError #1112) in extending MediaTraitBase

    Saverio Trioni

      Hello.

       

      I'm implementing a custom dynamic stream trait, which allows to use stream switching with standard progressive video.

       

      When I create the Trait (in the proxy element) a runtime error is thrown:

       

      ArgumentError: Error #1112: Discordancia del recuento de argumentos en coerción de clase.  Se esperaba 1; se obtuvo 4.

      at MyDynamicStreamTrait$cinit()

      at global$init()[MyDynamicStreamTrait.as:20]

      ...

       

      The constructor is not even being executed.

       

      Here are relevant extract of the code:

       

      ========= MyVideoElement.as ======================

      public class MyVideoElement extends ProxyElement {

      ...

      /*(in set wrappedElement):*/

      function processTraitAdd( type:String ):void {

      if (type == MediaTraitType.TIME) {

      var mytt:MyTimeTrait = new MyTimeTrait(loadTrait.netStream, wrappedElement.resource)

      addTrait( type, mytt );

      mydst = new MyDynamicStreamTrait(wrappedElement.resource, mytt, loadTrait);

      addTrait( MediaTraitType.DYNAMIC_STREAM, mydst);

      }

      }

        • 1. Re: Strange bug (ArgumentError #1112) in extending MediaTraitBase
          Saverio Trioni Level 1

          (sorry, I was in Eclipse-mode and hit Ctrl-S)

           

          ============= MyDynamicStreamTrait.as ==================

           

          public class MyDynamicStreamTrait extends MediaTraitBase

          {

           

          public function MyDynamicStreamTrait( resource:URLResource = null, timeTrait:MyTimeTrait = null, loadTrait:MyLoadTrait = null )

          {

          super( MediaTraitType.DYNAMIC_STREAM );

           

          this._timeTrait = timeTrait;

          this._loadTrait = loadTrait;

          this._netStream = loadTrait.netStream;

          this._resource = resource;

          trace( 'created' );

          }

           

           

          /* various logic */

           

          }

           

          ============================================================

           

           

          As soon as the 'new MyDynamicStreamTrait(wrappedElement.resource, mytt, loadTrait);' statement is executed, the ArgumentError is thrown.

          None of my other trait extensions is behaving this way.

           

          Any idea on what's happening?

          • 2. Re: Strange bug (ArgumentError #1112) in extending MediaTraitBase
            bringrags Level 4

            Traits are not meant to be extensible, they're a fixed set of APIs for controlling media in the system.  So instead of subclassing MediaTraitBase, you should have your custom trait extend DynamicStreamTrait.  Doing so will allow other parts of the system that are dynamic-streaming-aware to work with your implementation.

            • 3. Re: Strange bug (ArgumentError #1112) in extending MediaTraitBase
              Saverio Trioni Level 1

              The first version of the class was actually extending DynamicStreamTrait, but the same error happened, no difference.

               

              Anyway I have multiple extended traits, most of all for seek-ahead and for time calculations, and I never met any problem like this.

               

              Maybe I'm doing it the wrong way:

               

              The point is that I have different progressive streams for the same content, then, when a user indicates a quality change, I use some metadata of the newly selected stream to know when to open the new stream, and oon the exact time of the keyframe of the new stream I make the switch.

               

              This behavior seems what's intended "semantically" for a DynamicStreamTrait without autoSwitch.

               

              How could I do this without extending DynamicStreamTrait?

              • 4. Re: Strange bug (ArgumentError #1112) in extending MediaTraitBase
                bringrags Level 4

                Extending DynamicStreamTrait is an appropriate solution, I was simply pointing out that extending MediaTraitBase is not.  My hunch is that the ArgumentError is generated because you're passing the wrong set of parameters into DynamicStreamTrait's constructor (via the "super" call).  The params should be:

                 

                autoSwitch:Boolean, currentIndex:int, numDynamicStreams:int

                 

                Note that all have optional values.  There's no need to pass in the MediaTraitType.DYNAMIC_STREAM_TRAIT param, as that's automatically generated by the DynamicStreamTrait class.  If that's not your issue, please repost with the trait class that extends DynamicStreamTrait.

                • 5. Re: Strange bug (ArgumentError #1112) in extending MediaTraitBase
                  Saverio Trioni Level 1

                  This is the constructor of the first attempt to extend the DynamicStreamTrait.

                   

                  public function MyDynamicStreamTrait( resource:URLResource = null, timeTrait:MyTimeTrait =

                  null, loadTrait:MyLoadTrait = null )

                  {

                       super( false, 0, 4 );

                       ...

                       (assign the custom traits to be referenced...)

                  }

                   

                  Anyway the constructor breaks before even executing an instruction.

                   

                  By the way, I'm using sprint 9, not trunk.

                  • 6. Re: Strange bug (ArgumentError #1112) in extending MediaTraitBase
                    bringrags Level 4

                    I don't see anything wrong with that snippet of code.  Can you post a small, compilable sample?