开发者

How to make a Netstream based Actionscript video player resize automatically to match the parent size?

开发者 https://www.devze.com 2023-02-15 11:43 出处:网络
(I am new to Actionscript and I am sorry if this is a simple question.) I am doing a media player in Actionscript and I have the following class hierarchy:

(I am new to Actionscript and I am sorry if this is a simple question.)

I am doing a media player in Actionscript and I have the following class hierarchy:

  • Main class, extends Sprite, and contains
    • VideoPlayer class, extends Sprite, contains a Video object and loads the videos using Netstream

The video player will be embedded in different applications with containers with different sizes. Is there a way to make the video player to resize according to the size of the parent container (as defined in the html / swfobject)?

I played with the "scaleMode" properties on the Main class and I managed to make the flash object to rescale according to the container, but the video has always the same size.

Additionally, I changed the "width" and "height" properties of the Video object, both manually and automatically using the metadata of the video clip, and the video dimensions see开发者_运维知识库m to be wrong - I have a swfobject with 320x240 and when I changed the size of the video to match the swfobject size, it rendered much smaller than 320x240.

Thanks in advance for the help.


try something like this

// get the video aspect ratio
// 1.33 (4/3)  | 640 x 480
// 1.77 (16/9) | 854 x 480
//trace(_video_width / _video_height);
videoAspectRatio    = _video_width / _video_height;

// check if video is larger than stage
// check which is larger: height or width
// set video size as the largers of height or width

// if video is a 4/3 aspect ratio
if( videoAspectRatio  < 1.4)
{
    myVideo.width   = _stageWidth / videoAspectRatio;   
    myVideo.height  = myVideo.width / videoAspectRatio;

    // if movie is still to small to the stage make it bigger
    if(myVideo.height < _stageHeight)
    {
            myVideo.width = myVideo.width * (_stageHeight/myVideo.height);
            myVideo.height = _stageHeight
    }
}
else
{
    myVideo.width   = _stageWidth;
    myVideo.height  = _stageWidth / videoAspectRatio;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消