I am building an AR using Niantic studio.
What I want to do is to make a bouncing sound when a physics simulated ball entity collides with another entity.
I would like to know how to get the sound to sound like it does on the iPhone!
In ecs.Audio, you can’t specify the playback start position like play( delay ) in Three.js Audio, right?
So, in order to always set the playback position to 0, I create a new entity for Audio and play it at the timing I want it to sound as follows.
const audioEid = world.createEntity()
if (Position.has(world, eid)) {
const blockPos = Position.cursor(world, eid)
// 2-2. set the same position for the generated entity
ecs.Position.set(world, audioEid, {
x: blockPos.x,
y: blockPos.y, { x: blockPos.x, y: blockPos.y, z: blockPos.z, z: blockPos.z, z: blockPos.z, z: blockPos.z
z: blockPos.z, }
})
}
ecs.Audio.set(world, audioEid, {
url: 'assets/ball.mp3', // specify actual sound effect file
paused: false, // if false, playback starts
loop: false,
volume: 1.0, }
})
setTimeout(() => {
world.deleteEntity(audioEid)
}, 1000)
The sound is normal on the simulator, but when viewed on an iPhone safari, the sound is often not heard.
- Even when it does, the timing of the sound is abnormally slow compared to the simulator (slow loading?).
- The first time the sound is played, but not after the second time.
- There is no error in the console.
- It often does not sound at all.
I saw inquiries about ecs.Audio
And I tried to make the sound play once with the interaction as shown below, but the above problem is not solved.
startEventDispatcher = async () => {
const audioEid = world_.createEntity()
ecs.Audio.set(world_, audioEid, {
url: 'assets/button.mp3', paused: false, { startEventDispatcher = async ( => { const audioEid = world_.createEntity()
paused: false, loop: false, { url: 'assets/button.mp3', url: 'assets/button.mp3', loop: false, loop: false
loop: false,
volume: 0.1, }
})
world_.events.dispatch(eid_, 'start') // dispatch event when clicked
}
// add a click event listener
uiContent.addEventListener('click', startEventDispatcher)
How can I fix it?
Could you help me?