使用AR.js启用图像跟踪时播放声音并设置姿势



我只想在图像跟踪打开时播放mp3,在关闭时停止声音。我不知道如何使用a-nft。。。这是使用AR.js.的图像跟踪

我想我需要添加脚本来检查图像跟踪是否打开和关闭。请给我任何建议。谢谢

<!DOCTYPE html>
<html lang="en">
<head>
<title>Sample: AR.js with Image Tracking</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdn.jsdelivr.net/gh/aframevr/aframe@1c2407b26c61958baa93967b5412487cd94b290b/dist/aframe-master.min.js"></script>
<script src="https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar-nft.js"></script>
</head>
<body>
<div class="arjs-loader">
<p>
Now Loading...<br>
Please prepare the marker image :)
</p>
</div>
<a-scene
vr-mode-ui="enabled: false;"
renderer="logarithmicDepthBuffer: true;"
embedded
arjs="trackingMethod: best; sourceType: webcam;debugUIEnabled: false;"
>
<a-nft
type="nft"
url="image path"
smooth="true"
smoothCount="10"
smoothTolerance=".01"
smoothThreshold="5"
>
<a-sound src="path/to/sample.mp3" autoplay="false"></a-sound>
</a-nft>
<a-entity camera></a-entity>
</a-scene>
<script>

</script>
<style>
body {
font-family: helvetica, arial, sans-serif;
margin: 0;
overflow: hidden;
}
.arjs-loader {
height: 100%;
width: 100%;
position: absolute;
top: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.8);
z-index: 9999;
display: flex;
justify-content: center;
align-items: center;
}
.arjs-loader p {
text-align: center;
font-size: 1.25em;
color: white;
}
</style>
</body>
</html>

如果您在资产中声明a声音,然后在实际的a声音中调用它,则可以为其提供一个ID。然后你就可以有一个自动脚本,可以播放和暂停。这个脚本可能需要一些调整,但应该可以使用:

<!DOCTYPE html>
<html lang="en">
<head>
<title>Sample: AR.js with Image Tracking</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdn.jsdelivr.net/gh/aframevr/aframe@1c2407b26c61958baa93967b5412487cd94b290b/dist/aframe-master.min.js"></script>
<script src="https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar-nft.js"></script>
<script>
window.onload = function() {
AFRAME.registerComponent('shoundhandler', {
init: function () {
var marker = this.el;
this.sound = document.querySelector("#sound");
marker.addEventListener('markerFound', function () {
this.sound.play();
}.bind(this));

marker.addEventListener('markerLost', function() {
this.sound.pause();
this.sound.currentTime = 0;
}.bind(this));
}
});
};
</script>
</head>
<body>
<div class="arjs-loader">
<p>
Now Loading...<br>
Please prepare the marker image :)
</p>
</div>
<a-scene
vr-mode-ui="enabled: false;"
renderer="logarithmicDepthBuffer: true;"
embedded
arjs="trackingMethod: best; sourceType: webcam;debugUIEnabled: false;"
>
<a-assets>
<a-asset-item src="path/to/sample.mp3"
preload="false" id="sound" response-type="arraybuffer" loop
crossorigin webkit-playsinline autoplay="false" playsinline>
</a-asset-item>
</a-assets>

<a-nft
type="nft"
url="image path"
smooth="true"
smoothCount="10"
smoothTolerance=".01"
smoothThreshold="5"
>
<a-sound src="#sound"></a-sound>
</a-nft>
<a-entity camera></a-entity>
</a-scene>
<script>

</script>
<style>
body {
font-family: helvetica, arial, sans-serif;
margin: 0;
overflow: hidden;
}
.arjs-loader {
height: 100%;
width: 100%;
position: absolute;
top: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.8);
z-index: 9999;
display: flex;
justify-content: center;
align-items: center;
}
.arjs-loader p {
text-align: center;
font-size: 1.25em;
color: white;
}
</style>
</body>
</html>

相关内容

  • 没有找到相关文章

最新更新