问题描述
您好我尝试使用PhoneGap的媒体对象播放音频内容,但我得到这个错误
未捕获的ReferenceError:不定义的媒体我碰到的PhoneGap文档的
Hi i try to use the phoneGap Media object to play audio content but i'm getting this errorUncaught ReferenceError:Media is not defined i'm getting this example of code from phonegap Documentation http://docs.phonegap.com/en/1.0.0/phonegap_media_media.md.html
我用下面的code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Media Example</title>
<script type="text/javascript" charset="utf-8" src="phonegap-1.4.1.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for PhoneGap to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
//
function onDeviceReady() {
playAudio("http://audio.ibeat.org/content/p1rj1s/p1rj1s_-_rockGuitar.mp3");
}
// Audio player
//
var my_media = null;
var mediaTimer = null;
// Play audio
//
function playAudio(src) {
// Create Media object from src
my_media = new Media(src, onSuccess, onError);
// Play audio
my_media.play();
// Update my_media position every second
if (mediaTimer == null) {
mediaTimer = setInterval(function() {
// get my_media position
my_media.getCurrentPosition(
// success callback
function(position) {
if (position > -1) {
setAudioPosition((position) + " sec");
}
},
// error callback
function(e) {
console.log("Error getting pos=" + e);
setAudioPosition("Error: " + e);
}
);
}, 1000);
}
}
// Pause audio
//
function pauseAudio() {
if (my_media) {
my_media.pause();
}
}
// Stop audio
//
function stopAudio() {
if (my_media) {
my_media.stop();
}
clearInterval(mediaTimer);
mediaTimer = null;
}
// onSuccess Callback
//
function onSuccess() {
console.log("playAudio():Audio Success");
}
// onError Callback
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
// Set audio position
//
function setAudioPosition(position) {
document.getElementById('audio_position').innerHTML = position;
}
</script>
</head>
<body>
<a href="#" class="btn large"
onclick="playAudio('http://audio.ibeat.org/content/p1rj1s/p1rj1s_
_rockGuitar.mp3');">Play Audio</a>
<a href="#" class="btn large" onclick="pauseAudio();">Pause Playing Audio</a>
<a href="#" class="btn large" onclick="stopAudio();">Stop Playing Audio</a>
<p id="audio_position"></p>
</body>
</html>
任何想法,请,谢谢ü非常
Any idea please , thank u very much
推荐答案
üř提供播放声音无法正常工作时,我在浏览器中打开该链接的链接我不是能够播放声音。
The link u r providing for playing sound is not working properly when I am opening the link in a browser I m not able to play sound.
所以恳请乌尔rockGuitar.mp3存储你的资产/ www文件夹内,同时播放该文件提供文件的src为
So kindly store ur rockGuitar.mp3 inside your assets/www folder and while playing that file provide the src of the file as
src= "/android_asset/www/rockGuitar.mp3";
newMedia= new Media(src,onSuccess1,onError);
或提供声音的src工作环节。
Or provide working link in the src of sound.
这篇关于利用媒体对象录制和播放设备上的音频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!