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

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

问题描述

我在android 4.4上使用Android SDK的v19部署在phonegap上。我有一个mp3文件在我的index.html文件相同的文件夹,我想使用html5音频标签。

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目录中的mp3s。

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.

使用Media插件的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>


  • 使用Media对象的当前实现是唯一的选项,

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

    探索的链接:

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

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