2014-11-21 127 views
0

我使用camendesign的VIDEO FOR EVERYBODY腳本在我的頁面上嵌入視頻元素,併爲那些沒有HTML5功能的用戶設置Flash播放器回退。將Javascript變量插入flashVars字符串

但我正在改變網頁被調用時動態加載的網址。除了對象嵌入參數標記中的flashVars字符串外,所有內容都可以正常解析。此params標籤的值需要爲URL編碼,因此我在頁面上呈現視頻之前有一點javascript,以便使用加載的值對海報圖像和視頻文件的url進行編碼。

我的問題是:我如何正確解析出兩個值,以便他們正確地完成flashVars值?

這裏是我的代碼:(因此,這是我運行一個Java站點,因此JAVA C:套)

<!DOCTYPE HTML> 
<c:set var="title" value="Blender Demo Reel 2013"/> 
<c:set var="file" value="bdr2013"/> 
<c:set var="poster" value="poster.jpg"/> 
<c:set var="width" value="960"/> 
<c:set var="height" value="540"/> 

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>New Video Player</title> 
</head> 

<script> 
    var posterEncode = encodeURIComponent("${poster}"); 
    var fileEncode = encodeURIComponent("${file}"); 
</script> 

<body> 

<div id="videoContainer"> 
    <video controls preload poster="${poster}" width="${width}" height="${height}"> 
     <source src="${file}.mp4" type="video/mp4"> 
     <source src="${file}.ogv" type="video/ogg"> 
     <source src="${file}.webm" type="video/webm"> 
     <object type="application/x-shockwave-flash" data="http://player.longtailvideo.com/player.swf" width="${width}" height="${height}"> 
      <param name="movie" value="http://player.longtailvideo.com/player.swf" /> 
      <param name="allowFullScreen" value="true" /> 
      <param name="wmode" value="transparent" /> 
      <param name="flashVars" value="controlbar=over&amp;image="+posterEncode+"&amp;file="+fileEncode+".mp4" /> 
      <img alt="Big Buck Bunny" src="${poster}" width="${width}" height="${height}" title="No video playback capabilities, please download the video below" /> 
     </object> 
    </video> 
</div> 

</body> 
</html> 

的源代碼,當我在瀏覽器中查看該回來爲這樣的:

<script> 
    var posterEncode = encodeURIComponent("poster.jpg"); 
    var fileEncode = encodeURIComponent("bdr2013"); 
</script> 

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>New Video Player</title> 
<body> 

<div id="videoContainer"> 
    <video controls preload poster="poster.jpg" width="960" height="540"> 
     <source src="bdr2013.mp4" type="video/mp4"> 
     <source src="bdr2013.ogv" type="video/ogg"> 
     <source src="bdr2013.webm" type="video/webm"> 
     <object type="application/x-shockwave-flash" data="http://player.longtailvideo.com/player.swf" width="960" height="540"> 
      <param name="movie" value="http://player.longtailvideo.com/player.swf" /> 
      <param name="allowFullScreen" value="true" /> 
      <param name="wmode" value="transparent" /> 
      <param name="flashVars" value="controlbar=over&amp;image="+posterEncode+"&amp;file="+fileEncode+".mp4" /> 
      <img alt="Big Buck Bunny" src="poster.jpg" width="960" height="540" title="No video playback capabilities, please download the video below" /> 
     </object> 
    </video> 
</div> 

</body> 
</html> 
+0

爲什麼不在服務器端使用Java中的'poster'和'file'進行URI編碼呢? – 2014-11-21 17:41:29

+0

但我是否仍然需要將這些變量插入到flashVars字符串中?這就是我在上述問題中所要求的。 – Murphy1976 2014-11-21 17:45:48

回答

0

你只是寫出HTML屬性。這裏不需要JavaScript。 URI編碼Java中的字符串,並把它們在Java中的變量,然後把它們在你的HTML就像你做其他任何Java變量:

<param name="flashVars" value="controlbar=over&amp;image=${posterEncoded}&amp;file=${fileEncoded}.mp4" /> 
+0

但是,然後我需要第二組視頻源標籤的變量,不是嗎? – Murphy1976 2014-11-21 18:37:15

+0

我不確定你在問什麼,但是更大的答案是:如果你只需要將值寫入HTML標記一次,那麼在服務器端執行。如果您需要在瀏覽器中動態更改值以響應用戶操作,則可能需要JavaScript,否則只需在Java中執行。 – 2014-11-21 18:50:33

+0

我期待做的是調用所有數據一次,對其進行編碼(如果需要),然後將其插入需要去的地方。視頻源src值和flashvars文件值之間的差異在於flashVars值需要URL編碼,而視頻源src值則不是。因此,如果有方法可以將此頁面上的所有數據都帶上,那麼將其放在需要的地方,然後以一次需要的格式爲理想。 – Murphy1976 2014-11-21 18:54:16

0

好哇!

<!DOCTYPE HTML> 
<c:set var="title" value="Blender Demo Reel 2013"/> 
<c:set var="file" value="bdr2013"/> 
<c:set var="poster" value="poster.jpg"/> 
<c:set var="width" value="960"/> 
<c:set var="height" value="540"/> 

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>New Video Player</title> 
</head> 

<body> 

<div id="videoContainer"> 
    <video controls preload poster="${poster}" width="${width}" height="${height}"> 
     <source src="${file}.mp4" type="video/mp4"> 
     <source src="${file}.ogv" type="video/ogg"> 
     <source src="${file}.webm" type="video/webm"> 
     <object type="application/x-shockwave-flash" data="http://player.longtailvideo.com/player.swf" width="${width}" height="${height}"> 
      <param name="movie" value="http://player.longtailvideo.com/player.swf" /> 
      <param name="allowFullScreen" value="true" /> 
      <param name="wmode" value="transparent" /> 
      <script> 
       var posterEncode = encodeURIComponent("${poster}"); 
       var fileEncode = encodeURIComponent("${file}"); 
       document.write("<param name='flashVars' value='controlbar=over&amp;image="+posterEncode+"&amp;file="+fileEncode+".mp4' />"); 
      </script> 
      <img alt="${title}" src="${poster}" width="${width}" height="${height}" title="${title}" /> 
     </object> 
    </video> 
</div> 

</body> 
</html> 

我扔的JavaScript encodeURIComponent函數和文件撰寫成,我需要動態PARAM線要和快變!像魅力一樣工作。