Import a sound and play it using Audio expo-av

Gustavo Albuquerque Lima
2 min readNov 27, 2020

Before teaching you how to do that, I had to learn this myself, because the documentation doens’t contain this specific situation very clearly, to play some audio that you recently imported.

First - You have to install the dependecies

$ expo install expo-av

$ expo install expo-document-picker

Second - Import inside your project

Importing the dependencies

Third - Then create a var to store the imported audio

Use ‘useState()’ for re-render the page when you choose some audio

Fourth - Inside the return page code, create a button to import the audio

Don’t forget to import the View, TouchbleHighlight, styles, and Text

Fifth - Create a function to import an audio

Use the DocumentPicker.getDocumentAsync() to open the file browser in the user cellphone, with the configuration ({type: ‘audio/*’}) to just allow the user to import audio

Sixth - Update the button ‘onPress’

Seventh - Create a button to play the imported audio

Eighth - Create the function to play the audio when the user clicks on the button

Getting the imported audio Uri, creating new Audio Sound, loading the imported audio, and playing it!

Nineth - Now just update the button ‘onPress’

Tenth - Now have Fun!!! Here are the full code:

And here are the full code in snack.expo.io for you test it or copy it

https://snack.expo.io/71LTgzZKc

Thanks for seeing this! I hope this article helped you!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Gustavo Albuquerque Lima
Gustavo Albuquerque Lima

Written by Gustavo Albuquerque Lima

Studies: React Native, Python, JavaScript, Node JS, C#, SQL, React.Js, Bootstrap, php, Pytorch and Numpy

Responses (1)

Write a response

issue: how to fix the app reloading after opening the picker?