如何使用HTML5音频标签使用PhoneGap的播放本地的MP3在Android? [英] How can I use html5 audio tags to play local mp3s on Android using phonegap?

查看:282
本文介绍了如何使用HTML5音频标签使用PhoneGap的播放本地的MP3在Android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我部署在Android 4.4与Android SDK中对PhoneGap的V19。我在同一个文件夹我的index.html文件,我想使用HTML5音频标签来播放MP3文件。

I am deploying on Android 4.4 with v19 of the Android SDK on phonegap. I have an mp3 file in the same folder as my index.html file that I want to play using html5 audio tags.

<html>
  <body>
  <audio controls>
    <source src='sound.mp3' type='audio/mpeg'>
  </audio>
  </body>
  <script type="text/javascript" src="cordova.js"></script>
</html>

它不工作,失败,出现以下内容:

It doesn't work and fails with the following:

I/AwesomePlayer(  124): setDataSource_l(URL suppressed)
E/        (  124): Failed to open file '/android_asset/www/sound.mp3'. (No such file or directory)

它看起来像一个路径问题,但我已经尝试了所有的排列我能想到的。我认为这是更根本的,像AwesomePlayer无法访问存储在android_asset目录中的MP3。

It looks like a path issue, but I've tried all permutations I can think of. I think it is more fundamental, like AwesomePlayer can't access mp3s that are stored in the android_asset directory.

使用媒体插件PhoneGap的工作正常,其他的答案都建议,但由于音频标签工作的外部媒体,和媒体的插件适用于国内媒体,好像这应该是很容易解决的。我也有一个很大的工作应用程序,使用音频标签无处不在,我真的不希望重写它使用媒体的插件。有一个简单的明显修复,或者我应该提交错误报告?

Using the Media plugin for phonegap works fine as other answers have suggested, but since audio tags work for external media, and the Media plugin works for internal media, it seems like this should be easily fixable. I also have a huge working app that uses audio tags everywhere and I really don't want to rewrite it to use the Media plugin. Is there an easy obvious fix, or should I submit a bug report?

推荐答案

让我总结,我发现从各种各样的问题是什么/在类似的话题答案:

Let me summarize what I found from various questions/answers on the similar topic:

  • 音频标签有点打破在Android的WebView。所以,是的,这是一个错误。
  • 使用音频标签播放本地文件正常工作的iOS和桌面浏览器
  • 播放本地文件从SD卡,适用于Android的:

  • the audio tag is kinda broken in the Android WebView. So yes this is a bug.
  • use of audio tag for playing local files works fine on iOS and desktop browsers
  • playing local files from SD cards works on Android:

<audio controls="controls">
   <source src="file:///sdcard/test.mp3" type="audio/mpeg"/> 
</audio>

  • 使用媒体对象的当前实现,如果你想在时刻发挥来自Android设备的文件是唯一的选择。

  • your current implementation using Media object is the only option if your would like to play files from Android device at the moment.

    链接探索:

    • https://groups.google.com/forum/#!topic/phonegap/PneF6j47yFY
    • Play sound on Phonegap app for Android
    • HTML5 audio not playing in PhoneGap App (Possible to use Media?)

    这篇关于如何使用HTML5音频标签使用PhoneGap的播放本地的MP3在Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆