Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to play audio file as soon as screen is loaded #13

Closed
inglesuniversal opened this issue Jan 28, 2018 · 3 comments
Closed

How to play audio file as soon as screen is loaded #13

inglesuniversal opened this issue Jan 28, 2018 · 3 comments

Comments

@inglesuniversal
Copy link

Hi, is there a way to play a local bundled audio file as soon as the component is loaded or rendered?

similar to on html

So that it is played as an intro sound without any required interaction from the user.

Thanks

@jorgegorka
Copy link

You just need to update the componentDidMount event to load the file and play it.

componentDidMount() {
  (async () => {
    await Audio.setAudioModeAsync({
      allowsRecordingIOS: false,
      interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX,
      playsInSilentModeIOS: true,
      shouldDuckAndroid: true,
      interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DO_NOT_MIX,
    });
    await this._updatePlaybackInstanceForIndex(playing);
    this._onPlayPausePressed();
    
  })();  
  (async () => {
    await Font.loadAsync({
      'cutive-mono-regular': require('./assets/fonts/CutiveMono-Regular.ttf'),
    });
    this.setState({ fontLoaded: true });
  })();
}

@santosrai
Copy link

I changed it but it says "Can't find variable:playing"

img_269c570e34c0-1

@cruzach
Copy link
Contributor

cruzach commented Aug 1, 2019

Hey, late follow-up here but I suggest going through the Audio documentation to see the best way of doing this

@cruzach cruzach closed this as completed Aug 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants