Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expo sound, how to get the duration of a sound

I have a sound object whose duration I need

this.soundObject = new Audio.Sound();
await this.soundObject.loadAsync(sound);

I've tried this, however the documentation says it only works for recordings.

this.soundObject.durationMillis

Is there something I'm overlooking? I can't seem to find a parameter for the duration.

like image 496
BiggerD Avatar asked Apr 06 '19 20:04

BiggerD


People also ask

What library should I use to play audio files in react native Expo?

React Native Sound is a library that allows you to easily play sound effects and music in your React Native apps. It's open-source, easy to use, and works on both iOS and Android.

Can we use Expo AV IN react native CLI?

If you create a bare React Native project through expo-cli by running expo init and choosing a Bare template, your project will have react-native-unimodules installed and configured for you. You can run this project by using react-native run-ios or react-native run-android rather than expo start .

How do I use Expo share?

Run your app with expo start --https to enable it. No local file sharing on web: Sharing local files by URI works on iOS and Android, but not on web. You cannot share local files on web by URI — you will need to upload them somewhere and share that URI.


1 Answers

The duration is stored in the status, it needs a promise to access

 this.soundObject.getStatusAsync()
      .then(function(result) {
        console.log(result.durationMillis)
      })
      .catch(failureCallback);
like image 102
BiggerD Avatar answered Sep 18 '22 07:09

BiggerD