4 Replies Latest reply on Aug 25, 2010 6:07 AM by Jason C MacDonald

    New scale mode - shrink to fit (RFC)

    _del_p_ Level 1

      Hi, not sure if this is the best place to put in requests for change with the OSMF code.


      I required a scale mode not currently in the OSMF.  I require a video to be as big as the video container, providing that the container isn't bigger than the video.  (bit like the letterbox mode, but you never enlarge it).

      So its ok to shrink the video, but not to enlarge it, at the same time the aspect ratio should be maintained.  It would also be handy to then be able to get whatever ratio was used to scale the video. I've already done this myself, but it would be a good addition to the OSMF.


        • 1. Re: New scale mode - shrink to fit (RFC)
          rshin Level 3



          Thanks for the suggestion. Seems like a good fit for layout feature.

          You could file this here as a feature request, so that we can take it into review process.



          Please state your use case for this feature briefly, and it would be helpful if you can mention why you'd need to create your own solution and what would be good if this is in framework if you have anything to list.  Since you have already work on this, it would be nice to share your approach/work.





          1 person found this helpful
          • 2. Re: New scale mode - shrink to fit (RFC)
            Jason C MacDonald

            Hi, I ran into the same requirement and decided to add this manually to the ScaleModeUtils and ScaleMode files.


            Reason: I'm creating a media player that has variable dimensions based on the end users implementation. A requirement for the player is to never resize images higher than their intrinsic size due to quality lose when scaling - these are professional photos and video where quality is key! Because this player can be any size and/or aspect ratio, I need to ensure that the images are fully viewable when the player is smaller than the intrinsic size. Hence, the addition below. The same requirement goes for SWF and video files too.


            ScaleModeUtils-  added at line 94

            case ScaleMode.NATIVE_OR_SMALLER:
                                     var availableHeightRatio:Number = availableWidth / availableHeight;
                                     var availableWidthRatio:Number = availableHeight / availableWidth;
                                     if (availableHeightRatio > 1) {
                                          var componentHeightRatio:Number
                                               = (intrinsicWidth || availableWidth) /
                                               (intrinsicHeight || availableHeight);
                                               = new Point
                                               (availableHeight * componentHeightRatio
                                               , availableHeight
                                     } else if (availableWidthRatio > 1) {
                                          var componentWidthRatio:Number
                                               = (intrinsicHeight || availableHeight) /
                                               (intrinsicWidth || availableWidth);
                                               = new Point
                                               availableWidth * componentWidthRatio
                                     } else {
                                               = new Point
                                               (intrinsicWidth || availableWidth
                                               , intrinsicHeight || availableHeight


            ScaleMode - addition

            public static const NATIVE_OR_SMALLER:String = "nativeOrSmaller";


            Message was edited by: Jason C MacDonald - Was missing a couple lines to cover width

            1 person found this helpful
            • 3. Re: New scale mode - shrink to fit (RFC)
              _del_p_ Level 1

              That's pretty much  exactly what I did, but I also added a public var so that I could get the ratio  that was used to shrink that video as well.


              I was thinking that  ideally there should be a custom scale mode where you give it a function and  that function sets the size, that way anyone that had a specific mode that  wasn't catered for could write there own without modifying the OSMF  code.


              I've been meaning to write something up and add it to the previous link, just not had the time yet!

              • 4. Re: New scale mode - shrink to fit (RFC)
                Jason C MacDonald Level 1

                The function idea is good too. Either solution would work well moving forward.