This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 57).
Expo VideoThumbnails
一个允许你从视频文件生成图片作为缩略图的库。
已弃用: Video Thumbnails 库已被弃用,改为使用expo-video中的generateThumbnailsAsync。expo-video-thumbnails不再接收补丁更新,并将在 SDK 56 中移除。
expo-video-thumbnails 允许你从视频文件生成一张图片作为缩略图。
安装
- npx expo install expo-video-thumbnailsIf you are installing this in an existing React Native app, make sure to install expo in your project.
用法
import { useState } from 'react'; import { StyleSheet, Button, View, Image, Text } from 'react-native'; import * as VideoThumbnails from 'expo-video-thumbnails'; export default function App() { const [image, setImage] = useState(null); const generateThumbnail = async () => { try { const { uri } = await VideoThumbnails.getThumbnailAsync( 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4', { time: 15000, } ); setImage(uri); } catch (e) { console.warn(e); } }; return ( <View style={styles.container}> <Button onPress={generateThumbnail} title="生成缩略图" /> {image && <Image source={{ uri: image }} style={styles.image} />} <Text>{image}</Text> </View> ); } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', }, image: { width: 200, height: 200, }, });
API
import * as VideoThumbnails from 'expo-video-thumbnails';
Methods
| Parameter | Type | Description |
|---|---|---|
| sourceFilename | string | An URI of the video, local or remote. |
| options(optional) | VideoThumbnailsOptions | A map defining how modified thumbnail should be created. Default: {} |
Create an image thumbnail from video provided via sourceFilename.
Promise<VideoThumbnailsResult>Returns a promise which fulfils with VideoThumbnailsResult.
Types
| Property | Type | Description |
|---|---|---|
| headers(optional) | Record<string, string> | In case |
| quality(optional) | number | A value in range |
| time(optional) | number | The time position where the image will be retrieved in ms. |