Skip to main content

getAudioDurationInSeconds()

已弃用

此功能已被弃用。请改用 parseMedia(),它更快并且支持更多格式。

@remotion/media-utils 工具函数包的一部分。

🌐 Part of the @remotion/media-utils package of helper functions.

以前称为 getAudioDuration().

🌐 Previously called getAudioDuration().

获取音频源的持续时间(以秒为单位)。Remotion 将创建一个不可见的 <audio> 标签,加载音频并返回持续时间。

🌐 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> - 音频文件的持续时间。

示例

🌐 Example

import {getAudioDurationInSeconds} from '@remotion/media-utils';
import music from './music.mp3';

const MyComp: React.FC = () => {
  const getDuration = useCallback(async () => {
    const publicFile = await getAudioDurationInSeconds(staticFile('voiceover.wav')); // 33.221
    const imported = await getAudioDurationInSeconds(music); // 127.452
    const remote = await getAudioDurationInSeconds('https://example.com/remote-audio.aac'); // 50.24
  }, []);

  useEffect(() => {
    getDuration();
  }, []);

  return null;
};

另请参阅

🌐 See also