开发者

Auto resize in JW Player

Is there any way we can make the JW Player auto resizable when it l开发者_如何学JAVAoads?

Like, for instance, if the movie file is smaller in dimensions than the player,then there is black background it. I want the movie to spread all over the black color.

Thanks in advance.


There are a couple of stretching options that can be set via flashvar. These include none (no stretching), exactfit (disproportionate), uniform (stretch with black borders) or fill (uniform, but completely fill the display). They're all listed on our flashvars page.

If you're looking to update the size of the player within the DOM, it may be possible, but it's certainly not recommended, as this would cause Flash to reload the player.

Best,

Zach

Developer, LongTail Video


The following works for me:

<html>
<script type="text/javascript" src="jwplayer.js"></script>
<script type="text/javascript">jwplayer.key="LicenceCodeGoesHere";</script>
<div id="container">This'll be the player</div>

<script type="text/javascript">
jwplayer("container").setup({
    file:"http://videoURLGoesHere",
    autostart:true,
    width: "100%",
    height: "98%",
ratio: "100%",
responsive: true,
    events:{
        onComplete: function() {
            window.location = "http://redirectGoesHere";
        }
    }

});

</script>
<a href="http://UrlGoesHere">Please click here to skip the video and load the main site</a> 
</html>

Hope this helps!


As far as resizing the player itself, as opposed to scaling the content inside it, JW Player has a resize function now, which you can combine with the onMeta event to resize the player to match the video dimensions. Note that I've only tried this on streaming video, so I'm not 100% sure the meta event works the same on file-based playback.

You might want to use the onMeta event to calculate the correct size, but wait until an onPlay event to actually call resize() - if you've got a still image loaded before playback begins, it'll still be up when you resize on the onMeta event, and it'll stretch but look a little weird for a second. This still happens at onPlay but it's faster.

In your jwplayer('video_id').setup() function, just include something like this in the options:

        events: {
          onMeta: function(event) {
            if(event.metadata.width != undefined && event.metadata.height != undefined && event.metadata.width != 0) {
              var playerWidth = 700;
              var playerHeight = (event.metadata.height/event.metadata.width)*playerWidth;
              jwplayer("video_id").resize(playerWidth, playerHeight);
            }
          }
        }

That's assuming you want to keep the width at 700 but scale the height of the player to fit the media file, and of course that your player has id "video_id" in the DOM.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜