3
我正在通過Android設備使用PhoneGap。PhoneGap - 無法播放本地聲音文件
我想播放本地的.wav文件,但得到一些錯誤。
我使用的示例代碼從
http://docs.phonegap.com/en/1.0.0/phonegap_media_media.md.html
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
//
function onDeviceReady() {
playAudio("sounds/menu-change.wav");
}
// Audio player
var my_media = null;
// Play audio
function playAudio(src) {
// Create Media object from src
my_media = new Media(src, onSuccess, onError);
// Play audio
my_media.play();
}
function onSuccess() {
console.log("playAudio():Audio Success");
}
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
我收到以下錯誤
09-29 16:06:49.934: D/CordovaLog(14944): JSCallback Error: Request failed.
09-29 16:06:49.934: D/CordovaLog(14944): file:///android_asset/www/js/cordova-2.0.0.js: Line 3698 : JSCallback Error: Request failed.
09-29 16:06:49.934: I/Web Console(14944): JSCallback Error: Request failed. at file:///android_asset/www/js/cordova-2.0.0.js:3698
09-29 16:06:49.944: D/DroidGap(14944): onMessage(onPageStarted,file:///android_asset/www/settings.html)
09-29 16:06:49.964: I/AudioSystem(14944): getting audio flinger
09-29 16:06:49.974: I/AudioSystem(14944): returning new audio session id
09-29 16:06:50.014: E/MediaPlayer(14944): error (1, -2147483648)
09-29 16:06:50.014: W/System.err(14944): java.io.IOException: Prepare failed.: status=0x1
09-29 16:06:50.014: W/System.err(14944): at android.media.MediaPlayer.prepare(Native Method)
09-29 16:06:50.014: W/System.err(14944): at org.apache.cordova.AudioPlayer.loadAudioFile(AudioPlayer.java:544)
09-29 16:06:50.014: W/System.err(14944): at org.apache.cordova.AudioPlayer.readyPlayer(AudioPlayer.java:468)
09-29 16:06:50.014: W/System.err(14944): at org.apache.cordova.AudioPlayer.startPlaying(AudioPlayer.java:212)
09-29 16:06:50.014: W/System.err(14944): at org.apache.cordova.AudioHandler.startPlayingAudio(AudioHandler.java:232)
09-29 16:06:50.014: W/System.err(14944): at org.apache.cordova.AudioHandler.execute(AudioHandler.java:75)
09-29 16:06:50.014: W/System.err(14944): at org.apache.cordova.api.PluginManager$1.run(PluginManager.java:192)
09-29 16:06:50.014: W/System.err(14944): at java.lang.Thread.run(Thread.java:1027)
09-29 16:06:50.494: D/CordovaLog(14944): JSCallback: Message from Server: cordova.require('cordova/plugin/Media').onStatus('abf853b7-3e45-f906-fc59-92d9f11e9a14', 1, 0);
09-29 16:06:50.494: D/CordovaLog(14944): file:///android_asset/www/js/cordova-2.0.0.js: Line 3669 : JSCallback: Message from Server: cordova.require('cordova/plugin/Media').onStatus('abf853b7-3e45-f906-fc59-92d9f11e9a14', 1, 0);
09-29 16:06:50.504: I/Web Console(14944): JSCallback: Message from Server: cordova.require('cordova/plugin/Media').onStatus('abf853b7-3e45-f906-fc59-92d9f11e9a14', 1, 0); at file:///android_asset/www/js/cordova-2.0.0.js:3669
09-29 16:06:50.504: D/CordovaLog(14944): JSCallback Error: TypeError: Cannot read property 'statusCallback' of undefined
09-29 16:06:50.504: D/CordovaLog(14944): file:///android_asset/www/js/cordova-2.0.0.js: Line 3670 : JSCallback Error: TypeError: Cannot read property 'statusCallback' of undefined
09-29 16:06:50.504: I/Web Console(14944): JSCallback Error: TypeError: Cannot read property 'statusCallback' of undefined at file:///android_asset/www/js/cordova-2.0.0.js:3670
它說這需要媒體的插件,但我有它在我的config.xml中啓用文件
<plugin name="Media" value="org.apache.cordova.AudioHandler"/>
任何幫助將不勝感激。
感謝