我创建了一个示例 phonegap 应用程序,该应用程序的目标是播放静态 mp3 文件。我已将文件放在以下位置/android_asset/www
文件夹下。
HTML5 内容如下:
<html>
<head>
<title>PhoneGap Back Button Example</title>
<script type="text/javascript" src="phonegap-1.2.0.js"></script>
<script type="text/javascript">
var myMedia = null;
var playing = false;
//Method for playing the audio Track1 file
function playAudio() {
if (!playing) {
myMedia.play();
document.getElementById('play').src = "images/pause.png";
playing = true;
} else {
myMedia.pause();`enter code here`
document.getElementById('play').src = "images/play.png";
playing = false;
}
} </script>
<body onload="onLoad()">
<h1>Audio Player</h1>
<p id="audio_position">0.000 sec</p>
<p>
//The Html page contains a dropdown of option from which we can select the source from where the media file can be played
<select id="playlist" onchange="updateMedia()">
<optionvalue="/android_asset/www/audio/track1.mp3">Asset</option>
</select>
</p>
<a href="#" onclick="playAudio()"><img id="play" src="images/play.png"></a>
<a href="#" onclick="stopAudio()"><img id="stop" src="images/stop.png"></a>
</body>
</html>
活动类如下:
package com.plugin.myapp;
import com.phonegap.DroidGap;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class MainActivity extends DroidGap
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// super.loadUrl("file:///android_asset/www/index.html");
WebView webview = new WebView(this);
setContentView(webview);
//Media.getContentUriForPath("/android_asset/www/audio/track1.mp3");
//this helps to load the html page
webview.loadUrl("file:///android_asset/www/audio/example.html");
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
}
}
问题可能是什么?