Javascript 将mp3声音添加到增强现实中,而不是播放
我不熟悉JavaScript,想在wikitude世界启动时添加一个mp3文件来播放,但它没有播放。没有音频 我使用wikitude网站上的教程将wikitude添加为Android应用程序的一部分 wikitude sdk的类声音文档 以下是音频的代码选择Javascript 将mp3声音添加到增强现实中,而不是播放,javascript,augmented-reality,wikitude,Javascript,Augmented Reality,Wikitude,我不熟悉JavaScript,想在wikitude世界启动时添加一个mp3文件来播放,但它没有播放。没有音频 我使用wikitude网站上的教程将wikitude添加为Android应用程序的一部分 wikitude sdk的类声音文档 以下是音频的代码选择 streamingSound = new AR.Sound("assets/soundtest.mp3", { onError : errorLoadingSound,
streamingSound = new AR.Sound("assets/soundtest.mp3", {
onError : errorLoadingSound,
onFinishedPlaying : readyToPlay,
onLoaded : readyToPlay,
});
streamingSound.load();
streamingSound.play();
下面是multiplepois.js文件的完整代码
var World = {
markerDrawable_idle: new AR.ImageResource("assets/lion.png"),
// New: a second image resource which represents a selected marker
markerDrawable_selected: new AR.ImageResource("assets/marker_selected.png"),
// New: a array holding a reference to all marker objects
markerList: [],
init: function initFn() {
AR.context.onLocationChanged = World.onLocationChanged;
// New: a custom callback which will be invoked when the user taps on an empty screen space
AR.context.onScreenClick = World.onScreenClick;
},
onLocationChanged: function onLocationChangedFn(latitude, longitude, altitude, accuracy) {
AR.context.onLocationChanged = null;
streamingSound = new AR.Sound("assets/soundtest.mp3", {
onError : errorLoadingSound,
onFinishedPlaying : readyToPlay,
onLoaded : readyToPlay,
});
streamingSound.load();
streamingSound.play();
}
// New: Markers are now created using the new operator.
// The marker definition is in `marker.js`.
// Title, description and location are supplied in the json compatible format
var poiData = {
"latitude": 31.580,
"longitude": 130.545,
"altitude": altitude,
"title": "Marker 1",
"description": "forever office"
};
World.markerList.push(new Marker(poiData));
poiData = {
"latitude": latitude,
"longitude": longitude - 0.5,
"altitude": altitude,
"title": "Marker 4",
"description": "West"
};
World.markerList.push(new Marker(poiData));
},
onScreenClick: function onScreenClickFn() {
for (var i = World.markerList.length - 1; i >= 0; i--) {
if (World.markerList[i].isSelected) {
World.markerList[i].setDeselected(World.markerList[i]);
}
}
}
};
World.init();
您可以使用SDK附带的ADE(ADE.js)来使用桌面浏览器检查任何js错误。JS错误也将在logcat中报告在Android上。然而,根据手机的不同,这可能很难发现
在桌面浏览器中使用ADE检查代码会发现:
Uncaught ReferenceError: errorLoadingSound is not defined
如果您只想播放声音:
streamingSound = new AR.Sound("assets/soundtest.mp3");
streamingSound.play();
免责声明:我为Wikitude工作