2012-04-14 110 views
8

我對這一切都很陌生,無法弄清楚在調整窗口大小或方向更改時如何調整我用於家庭媒體服務器的Flash播放器的大小。我將玩家大小視爲視口的大小。我已經搜索並嘗試了各種版本,但他們不工作,這很可能是由於我缺乏知識。 下面的大部分代碼已經完成了,我已經評論了我在這裏添加的內容以供參考。用於flash播放器的視口大小調整事件

Link to a sample

viewport.js(由我添加)

var width = $(window).width(); 
var height = $(window).height(); 

HTML

<html xmlns="http://www.w3.org/1999/xhtml"> 

<head> 
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> 
<title>Gizmo play_flash</title> 
<meta name="keywords" content="" /> 
<meta name="description" content="" /> 
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" /> 
<script type="text/javascript" src="scripts/jwplayer.js"></script> 
<script type="text/javascript" src="jquery/jquery.js"></script> 
<script type="text/javascript" src="scripts/viewport.js"></script> 
<noscript><meta http-equiv="refresh" content="2; URL=noscript.html"></noscript> 
</head> 

<body style="margin: 0; padding: 0; background-color: #000000"> 
<div id="outer"> 

    <div class="player_wrapper" style="width: 100%; height: 100%; margin:0px auto;"> 
     <div id="player"> 
      Loading the video player ... 
     </div> 
    </div> 

    <script type="text/javascript"> 
     jwplayer('player').setup({ 
      'flashplayer': 'scripts/player.swf', 
      'file': '[File.FlashLink]', 
      'autostart': 'true', 
      'duration': '[File.Duration]', 
      'provider': 'scripts/jrmediaprovider.swf', 
      'skin': 'scripts/glow.zip', 
        <!--begin mod--> 
      'width': width - 5, 
      'height': height - 5 
        <!--endmod--> 
     }); 

     jwplayer('player').onComplete(
      function(event) { 
       try { 
        window.Gizmo.onComplete(); 
       } catch (err) { } 
      } 
     ); 
    </script> 
</div> 
</body> 
</html> 
+1

我花了幾天現在正在尋找一個解決這個問題。不幸的是,在移動設備上無法實現這一點,請參閱:http://quirksmode.org/dom/events/resize_mobile.html – 2014-10-31 03:04:15

回答

20

只需綁定到window對象的resizeorientationChange事件和使用日獲得新的寬度和高度後使用方法JW Playerresize

就是這樣。

$(window).on('resize orientationChange', function(event) { 
    var width = $(window).width(); 
    var height = $(window).height(); 
    jwplayer('player').resize(width, height); 
}); 
+0

我不知道該怎麼做。就像我說的,我是一個完整的NuB。我甚至不知道它會去哪裏。 (js或html) – user1333680 2012-04-14 21:15:24

1

使用DOM API來檢測視調整大小:

window.addEventListener('resize', (ev) => { 
    console.log(window.innerWidth, window.innerHeight); 
});