2013-10-17 208 views
0

我想用jplayer只是簡單的播放一個簡單的html頁面,我有mp3的軌道,並已將其轉換爲m4a和ogg,但不能得到任何他們的工作。所有的路徑是正確的,我的標記如下:Jplayer沒有播放音樂文件,mp3,ogg和m4a

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> 
<script src="/jplayer/jquery.jplayer.min.js"></script> 
<script type="text/javascript"> 

    $(document).ready(function(){ 
     $("#jquery_jplayer_1").jPlayer({ 
     ready: function() { 
      $(this).jPlayer("setMedia", { 
       mp3: "/media/02 Cello Concerto _Overture_.mp3" 
      }); 
      }, 
      solution:"flash,html", 
      swfPath: "jplayer", 
      supplied: "mp3" 
     }); 
    }); 

    var _gaq = _gaq || []; 
    _gaq.push(['_setAccount', 'UA-44543565-1']); 
    _gaq.push(['_trackPageview']); 

    (function() { 
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 
    })(); 

</script> 
</head> 

<body style="text-align: center; background: url(images/bg.jpg) no-repeat center center; width: 100%; height: 100%; font-family: helvetica, arial; margin: 0px;"> 
    <div id="jquery_jplayer_1" class="jp-jplayer"></div> 

回答

0

從我在你的代碼中看到,這可能有多種原因:

  1. JPlayer可能無法找到「jplayer.swf」 。嘗試添加完整路徑。因爲你只給它mp3,所以它會在firefox中使用flash fallback。
  2. 您的文件名「/ media/02 Cello Concerto Overture .mp3」包含jPlayer可能無法正確處理的空格。
  3. 您應該始終向jPlayer音頻播放器提供mp3和m4a。否則,您可能無法在某些平臺上播放(例如,您的情況爲ios)。

編輯

您還沒有發出播放命令:

... 
$(document).ready(function(){ 
    $("#jquery_jplayer_1").jPlayer({ 
    ready: function() { 
     $(this).jPlayer("setMedia", { 
      mp3: "/media/02 Cello Concerto _Overture_.mp3" 
     }).jPlayer("play"); 
     }, 
     solution:"flash,html", 
     swfPath: "jplayer", 
     supplied: "mp3" 
    }); 
}); 
... 
0

不知怎的jPlayer甚至沒有編碼(是encodeURI/encodeURIComponent方法)後,支持在網址空間。嘗試重命名文件並刪除空格。