7 Replies Latest reply on May 16, 2013 8:44 AM by Syberkitten

    MediaFactory Video Smoothing

    edduddiee

      I currently have a MediaFactory which creates my media elements. However, this returns a generic MediaElement rather than an instance of a VideoElement. What want to be able to do is set smoothing to true on the elements returned but I can't seem to find a way to gain access to the VideoElement properties. Any ideas on how I would do this?

        • 1. Re: MediaFactory Video Smoothing
          Edwin van Rijkom Level 2
          var media:MediaElement = factory.createMediaElement(...);
          var video:VideoElement = media as VideoElement;
          if (video != null)
          {
             video.smoothing = true;
          }
          
          • 2. Re: MediaFactory Video Smoothing
            edduddiee Level 1

            When using trying that the `video` variable is always set too null so it never enters the if statement. If it helps this is the code I am using to create the media element where `url` is a string to a m4v file:

             

             

            var element:MediaElement = factory.createMediaElement(new URLResource(url));
            var video:VideoElement = element as VideoElement;
            
            • 3. Re: MediaFactory Video Smoothing
              bringrags Level 4

              If you're not getting a VideoElement back from createMediaElement then that probably means that the URL passed in is not a video URL (or doesn't appear to be one).  Does the result come back as null, or as a different type of MediaElement?  What's the URL that you're passing in, does it have a file extension (assuming it's HTTP-based)?  If not (or if it has a non-video extension), you might need to indicate that it's a video by setting resource.mediaType to MediaType.VIDEO.

              • 4. Re: MediaFactory Video Smoothing
                edduddiee Level 1

                I am using this with a m4v manifest file. It would seem this returns a M4VElement rather than a VideoElement like I was expecting. Sorry for the confusion. In this case how would I go about getting the video produced by the m4v smoothed? If it helps the m4v file will sometimes have a single progressive file and at other times have a list of dynamic streaming items.

                • 5. Re: MediaFactory Video Smoothing
                  bringrags Level 4

                  I assume you mean F4MElement (rather than M4VElement).  The F4MLoader uses a MediaFactory to create VideoElements.  So one way to fix this would be to have F4MLoader work with a MediaFactory which always generates VideoElement's that have smoothing enabled.  First, you'd need to create a subclass of MediaFactory that generates smoothed VideoElements:

                   

                  public class SmoothedMediaFactory extends MediaFactory

                  {

                     ...

                     // The init() method gets invoked by the constructor.  See DefaultMediaFactory.as for a similar approach.

                     private function init():void

                     {

                              netLoader = new NetLoader();
                              addItem
                                  ( new MediaFactoryItem
                                      ( "my.custom.elements.video"
                                      , netLoader.canHandleResource
                                      , function():MediaElement
                                          {
                                              var videoElement:VideoElement = new VideoElement(null, netLoader);
                                              videoElement.smoothing = true;
                                               return videoElement;
                                           }
                                      )
                                  );       
                     }

                     ...

                  }

                   

                  Then, use this MediaFactory with the F4MLoader that's passed to your F4MElement:

                   

                  var f4mLoader:F4MLoader = new F4MLoader(new SmoothedMediaFactory());

                  mediaPlayer.media = new F4MElement(resource, f4mLoader);

                   

                  You could migrate the above two lines into a MediaFactoryItem that gets added to a MediaFactory, so that someone could work directly with a MediaFactory to create smoothed VideoElements (i.e. without having to know about F4MLoader, F4MElement, etc.).

                  • 6. Re: MediaFactory Video Smoothing
                    Syberkitten Level 1

                    it doesn't seem to work, considering my custom

                    custom media factory class has this code for the f4mloader:

                     




                    f4mLoader = new F4MLoader(null);



                    addItem



                    ( new MediaFactoryItem




                    ( "org.osmf.elements.f4m"





                    , f4mLoader.canHandleResource





                    , function():MediaElement





                    {






                    return new F4MElement(null, f4mLoader);





                    }




                    )



                    );

                     

                     

                    as i understand, what you have written relates to the regular netLoader, and not the f4mloader.

                    when i do try to implement your solution as is, i simpy get an error saying Stream not Found (media error)

                     

                    Is there no way to pass a scope function into the init process of the media factory

                    and get access to its objects, video element amongs them, or something like that?

                     

                    any help is appreciated

                    • 7. Re: MediaFactory Video Smoothing
                      Syberkitten Level 1

                      found a good solution in this article:

                      http://nils.realeyesmedia.com/?p=94

                       

                      basically the idea is listen to a trait_add event,

                      check if the MediaElementEvent is of type MediaElementEvent.TRAIT_ADD

                      and if the traitType == MediaTraitType.DISPLAY_OBJECT

                       

                      then simply smooth the display object.

                       

                      code sample:




                      mediaElement.addEventListener(MediaElementEvent.TRAIT_ADD,function (e:MediaElementEvent) {









                      if (e.type == MediaElementEvent.TRAIT_ADD && e.traitType == MediaTraitType.DISPLAY_OBJECT) {





                      var displayObject:Object = (mediaPlayer.media.getTrait(MediaTraitType.DISPLAY_OBJECT) as DisplayObjectTrait).displayObject;





                      //Set the smoothing value to what you want.





                      displayObject.smoothing = true;




                      }



                      });