HTML5<音频>标签不工作在Android的web视图视图、音频、标签、工作

2023-09-05 04:28:11 作者:相关二元次的推荐>>

在HTML5音频标签似乎并没有在Web视图工作,如果源文件存储在本地。 即。

the HTML5 audio tag doesn't seem to work in the web view if the source file is stored locally. i.e.

<audio controls="controls">
   <source src="my_local_audio_file.mp3" type="audio/mpeg" />
</audio>

它的工作原理时,该文件是从服务器访问像 SRC =htt​​p://example.com/audio.mp3

我在Android ICS尝试。

I am trying it on Android ICS.

有一些变通的规定这里。但我不明白为什么这个问题发生。

There are a few workarounds as stated here . But i don't understand why this problem is occurring.

任何解决方案或见解,为什么发生这种情况?

Any solutions or insights as to why this is happening?

感谢你。

推荐答案

这只是alternet的方式来实现目标,从HTML文件播放音频

this is just alternet way to achieve goal to play audio from html file

使用媒体播放器( http://developer.android.com/reference/android Android系统/media/MediaPlayer.html )用于播放音频。 你可以从你写在HTML文件中的JavaScript调用Android的功能。

use Mediaplayer (http://developer.android.com/reference/android/media/MediaPlayer.html) of Android for playing audio. you can invoke function of android from javascript that you have written in HTML file..

这是例子,你如何可以调用函数从JavaScript code用Java编写的文件

this is example of how you can invoke function written in java file from javascript code

WebView webView = (WebView) findViewById(R.id.webview);
webView.addJavascriptInterface(new WebAppInterface(this), "Android");
--------------------------------
public class WebAppInterface {

    Context mContext;
    /** Instantiate the interface and set the context */
    WebAppInterface(Context c) {
        mContext = c;
    }

    /** Show a toast from the web page */
    @JavascriptInterface
    public void showToast(String toast) {
        Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
    }
}

---------------------------
java sript code

<input type="button" value="Say hello" onClick="showAndroidToast('Hello Android!')" />

<script type="text/javascript">
    function showAndroidToast(toast) {
        Android.showToast(toast);
    }
</script>

这样,您援引的Andr​​oid code音频。