getAudioDurationInSeconds()
Part of the @remotion/media-utils
package of helper functions.
Previously getAudioDuration()
Gets the duration in seconds of an audio source. Remotion will create an invisible <audio>
tag, load the audio and return the duration.
Arguments
src
A string pointing to an audio asset
Return value
Promise<number>
- the duration of the audio file.
Example
tsx
import {getAudioDurationInSeconds } from "@remotion/media-utils";importmusic from "./music.mp3";constMyComp :React .FC = () => {constgetDuration =useCallback (async () => {constimported = awaitgetAudioDurationInSeconds (music ); // 127.452constpublicFile = awaitgetAudioDurationInSeconds (staticFile ("voiceover.wav")); // 33.221constremote = awaitgetAudioDurationInSeconds ("https://example.com/remote-audio.aac"); // 50.24}, []);useEffect (() => {getDuration ();}, []);return null;};
tsx
import {getAudioDurationInSeconds } from "@remotion/media-utils";importmusic from "./music.mp3";constMyComp :React .FC = () => {constgetDuration =useCallback (async () => {constimported = awaitgetAudioDurationInSeconds (music ); // 127.452constpublicFile = awaitgetAudioDurationInSeconds (staticFile ("voiceover.wav")); // 33.221constremote = awaitgetAudioDurationInSeconds ("https://example.com/remote-audio.aac"); // 50.24}, []);useEffect (() => {getDuration ();}, []);return null;};