【问题标题】:error while playing mp3 from assets folder phonegap(Cordova)从资产文件夹phonegap(Cordova)播放mp3时出错
【发布时间】:2015-05-29 07:34:11
【问题描述】:

我刚开始学习phonegap,但是当我点击播放按钮播放assets 文件夹中的mp3 时,我收到了错误alert('no audio support!');。我搜索了很多播放 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>

【问题讨论】:

  • 我改进了您的措辞并添加了您之前遗漏的细节。这应该可以帮助您获得答案。
  • 对不起,我错了。如果你曾经以浮动视图服务的名义,我可以很快得到。
  • 别担心,感谢:),你也可以给我发电子邮件

标签: android cordova phonegap-plugins phonegap-build


【解决方案1】:

@quick learner,你在为哪个操作系统做这个?您在哪个操作系统上遇到问题?您的代码显示 Windows、iOS 和 Android。此代码可能适用于 Android。我有working examples for iOS and Android。 --杰西

【讨论】:

  • @quicklearner,好的。首先清理你的代码。 Windows 和 iOS 的这些额外点没有很好的记录,因此它们可能会在您的脑海中增加噪音。在此处下载我的演示:codesnippets.altervista.org/examples/phonegap/demos/… 您想要 Phonegap-Media-Test FWIW,mp3 已记录可与 Android 一起使用,但我认为您需要正确的 SDK 级别。如果你像我一样使用 OGG,那没关系。
  • 好吧,我阅读并感谢您的关注...我使用了代码但仍然无法播放...
  • 我最近发现Phonegap CLI 的路径系统与Phonegap Build 不同。删除所有内容,只需播放音频,然后将其添加回来。您不需要 jquery、jquerymobile 或 toast 来播放音频。您的问题很简单,但是您选择的工具会产生噪音,而不是解决方案。我的第一个音频应用没有 GUI,它只是播放声音。
  • 我之前在google groups上发布了信息。这是网址groups.google.com/forum/#!topic/phonegap/J6kWRdmtmIg
  • 我已经给了你我的代码,用于播放音频的工作应用程序 - 已经三遍了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-04
  • 2015-02-19
  • 2018-06-30
  • 1970-01-01
相关资源
最近更新 更多