播放本地音频文件的Andr​​oid的WebView应用音频文件、Andr、WebView、oid

2023-09-07 16:33:36 作者:江湖梦告吹

我有一个简单的Andr​​oid的WebView应用程序,用内置的PhoneGap构建。当试图播放的包含在APK本地MP3文件的,没有任何反应。但是,如果我拉一个MP3从网络上它的工作原理。

I have a simple Android webview app, built with Phonegap Build. When trying to play a local mp3 file that's included in the APK, nothing happens. However, if I pull an mp3 from the web it works.

例如。

<audio src="www.example.com/01.mp3" > WORKS JUST FINE

<audio src="01.mp3" > DOES NOT WORK

我是新的Andr​​oid开发,所以我只能猜测,该文件是某种不通Android的媒体播放器。下面是错误的链接/从我的日志文件中警告,如果这能帮助阐明问题的任何灯光。

I'm new to Android development, so I can only guess that the file is somehow inaccessible by Android's media player. Here's a link to the errors/warnings from my log file if that helps shed any light on the problem.

http://pastebin.com/isS542RE

推荐答案

我有工作使用PhoneGap的传媒类。我一定是做错了什么起初,但我不知道是什么。通过媒体对象来访问它的正确方法是西蒙表示previously:玛雅=新媒体(/ android_asset / WWW /请将test.mp3);

I have it working using Phonegap's Media class. I must have been doing something wrong initially, but I'm not sure what. The proper way to access it through the media object is as Simon stated previously: myMedia = new Media("/android_asset/www/test.mp3");

您必须把完整的路径视传媒类默认为相对路径/ SD卡目录。

You have to put the full path as the media class defaults to the /SDCARD directory on relative paths.

西蒙也有很大的写了有关使用多媒体类:http://simonmacdonald.blogspot.com/2011/05/using-media-class-in-phonegap.html?m=1

Simon also has a great write up about using the media class: http://simonmacdonald.blogspot.com/2011/05/using-media-class-in-phonegap.html?m=1

对于HTML5的方法和使用AUDIO标签,我还不能确定为什么它不能对本地文件。 PhoneGap的传媒类工作得很好,但并可能是一个更可靠的解决方案,无论如何。 PhoneGap的FTW!

As for the HTML5 method and using the AUDIO tag, I'm still not certain why it fails on local files. Phonegap's media class works just fine though and is probably a more reliable solution anyhow. Phonegap FTW!