2015-05-29 55 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

好吧,我读过它,并感谢您的关注...我使用了代码,但仍然无法播放它... –

相关问题