Skip to main content

getGifDurationInSeconds()

属于 @remotion/gif 软件包的一部分

🌐 Part of the @remotion/gif package

v3.2.22

获取 GIF 的持续时间(以秒为单位)。

🌐 Gets the duration in seconds of a GIF.

note

远程 GIF 需要支持 CORS

更多信息

参数

🌐 Arguments

src

指向 GIF 资源的字符串

🌐 A string pointing to a GIF asset

返回值

🌐 Return value

Promise<number> - GIF 的持续时间,以秒为单位,不考虑它是否循环播放。

示例

🌐 Example

import {getGifDurationInSeconds} from '@remotion/gif';
import gif from './cat.gif';

const MyComp: React.FC = () => {
  const getDuration = useCallback(async () => {
    const imported = await getGifDurationInSeconds(gif); // 127.452
    const publicFile = await getGifDurationInSeconds(staticFile('giphy.gif')); // 2.10
    const remote = await getGifDurationInSeconds('https://media.giphy.com/media/xT0GqH01ZyKwd3aT3G/giphy.gif'); // 3.23
  }, []);

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

  return null;
};

另请参阅

🌐 See also