Audio not playing until phone touched

Hello,

I have a very simple scene where I’ve added a script to my image target so that it plays audio when the image target appears, and stops when the image target disappears.

Here is the code attached to my image target.

import * as ecs from '@8thwall/ecs'

// Register a new component called 'Moon'
ecs.registerComponent({
  name: 'dev',
  schema: {
    // Define the schema for the component
    // distance: ecs.f32,
    // duration: ecs.f32,
  },
  schemaDefaults: {
    // Define the default values for the schema (empty in this case)
    // distance: 3,
    // duration: 10000,
  },
  data: {
    // Define the initial data for the component (empty in this case)
  },
  add: (world, component) => {
    console.log('inside add')
    world.events.addListener(world.events.globalId, 'reality.imagefound', (e) => {
      console.log(e)
      ecs.Audio.set(world, component.eid, {
        url: 'assets/its_music.mp3',
        volume: 1,
        loop: false,
        paused: false,
        pitch: 1,
        positional: false,
        refDistance: 1,
        distanceModel: 'inverse',
        rolloffFactor: 1,
        maxDistance: 10000,
      })
    })

    world.events.addListener(world.events.globalId, 'reality.imagelost', (e) => {
      ecs.Audio.remove(world, component.eid)
    })
  },
  tick: (world, component) => {
    // Define the behavior of the component on each tick (empty in this case)
  },
  remove: (world, component) => {
    // Define the behavior of the component when it is removed (empty in this case)
  },
})

However, when I publish my app it does not play the audio until I first touch my phone. It doesn’t matter where I touch, but it doesn’t play any audio until I do. I noticed this also on the basic example of playing audio where it doesn’t play any world audio until I touch the screen.

Are there any suggestions for a workaround? Any help would be greatly appreciated, if you need to to supply anymore information please let me know.

Thank you!

Hi Andrew,

Welcome to the forum!

This is unfortunately a side-effect of the browser’s Audio policy, and something we’re actively looking into improving. Right now the browser, not 8th Wall, requires that you tap the page at least once before audio can be played.