2015-05-29 30 views
1

我剛開始學習phonegap,但我收到錯誤alert('no audio support!');當我點擊播放按鈕播放和從assets文件夾中的MP3。我尋覓了大量的代碼來播放MP3和我迄今如下所示:從資產文件夾phonegap(科爾多瓦)播放mp3時出錯

<!DOCTYPE html> 

<html> 
<head> 
<meta charset="utf-8" /> 
<meta name="format-detection" content="telephone=no" /> 
<meta name="msapplication-tap-highlight" content="no" /> 
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 --> 
<meta name="viewport" 
    content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" /> 
<link rel="stylesheet" type="text/css" href="css/index.css" /> 
<link rel="stylesheet" 
    href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css"> 
<script src="http://code.jquery.com/jquery-1.11.2.min.js"></script> 
<script 
    src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> 
<title>Hello World</title> 

<script type="text/javascript" src="js/Toast.js"></script> 
<script> 
    function playStream() { 
     try { 
      var myaudio = new Media('/android_asset/www/audio/limelight.mp3'); 
      //alert ("ffff"); 

      myaudio.id = 'playerMyAdio'; 
      myaudio.play(); 
     } catch (e) { 
      alert('no audio support!'); 
     } 
    } 

    function getMediaURL(s) { 
     if (device.platform.toLowerCase() === "android") 
      return "/android/assets/www/" + s; 
     return s; 
    } 

    function stopStream() { 
     try { 
      myaudio.pause(); 
     } catch (e) { 
      alert('no audio support!'); 
     } 
    } 
</script> 

</head> 
<body> 
    <div data-role="page"> 
     <div data-role="header" data-position="fixed" data-theme="b"> 
      <h1>Play AUdio</h1> 
     </div> 
     <div data-role="content"> 
      <button onClick="playStream()">play</button> 
      <br /> 
      <button onClick="stopStream()">stop</button> 
      <br /> 
     </div> 
    </div> 
</body> 
</html> 
+0

我已經改進了你的措詞並增加了你之前錯過的細節。這應該有助於你得到答案。 –

回答

0

@quick學習者,其OS,你這樣做的?你遇到哪些操作系統問題?您的代碼顯示Windows,iOS和Android。此代碼可能適用於Android。我有working examples for iOS and Android。 --Jesse

+0

m學習Android ... –

+0

@quicklearner,好的。首先清理你的代碼。 Windows和iOS的這些額外點沒有很好的記錄,所以它們可能會增加噪音。在這裏下載我的演示:http://codesnippets.altervista.org/examples/phonegap/demos/PUBLIC.Apps.html你想* Phonegap-Media-Test * FWIW,mp3被記錄爲可以與Android一起工作,但我認爲你需要正確的SDK級別。如果你像我一樣使用OGG,那麼這沒關係。 – JesseMonroy650

+0

好吧,我讀過它,並感謝您的關注...我使用了代碼,但仍然無法播放它... –

相關問題