Expo

Documentation

VideoThumbnails

Platform Compatibility

Android DeviceAndroid EmulatoriOS DeviceiOS SimulatorWeb

For managed apps, you'll need to run expo install expo-video-thumbnails. To use it in a bare React Native app, follow its installation instructions.

import React from 'react';
import { StyleSheet, Button, View, Image, Text } from 'react-native';
import * as VideoThumbnails from 'expo-video-thumbnails';

export default class App extends React.Component {
  state = {
    image: null,
  };

  generateThumbnail = async () => {
    try {
      const { uri } = await VideoThumbnails.getThumbnailAsync(
        'http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4',
        {
          time: 15000,
        }
      );
      this.setState({ image: uri });
    } catch (e) {
      console.warn(e);
    }
  };

  render() {
    const { image } = this.state;
    return (
      <View style={styles.container}>
        <Button onPress={this.generateThumbnail} title="Generate thumbnail" />
        {image && <Image source={{ uri: image }} style={{ width: 200, height: 200 }} />}
        <Text>{image}</Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
});

import * as VideoThumbnails from 'expo-video-thumbnails';

Create an image thumbnail from video provided via uri.

Arguments

  • uri (string) -- URI of the video.
  • options (object) -- A map defining how modified thumbnail should be created:
    • compress (number) -- A value in range 0.0 - 1.0 specifying compression level of the result image. 1 means no compression (highest quality) and 0 the highest compression (lowest quality).
    • time (number) -- The time position where the image will be retrieved in ms.
    • headers (object) -- In case uri is a remote uri, headers object passed in a network request.

Returns

Returns { uri, width, height } where uri is a URI to the created image (useable as the source for an Image/Video element), width, height specify the dimensions of the image.