import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Image,
  NativeModules
} from 'react-native';
import fs from 'react-native-fs';

const savePath = fs.DocumentDirectoryPath + '/example.mp4';
const videoURL = 'http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4';

class MediaMetaSample extends Component {

  constructor(props) {
    super(props);

    this.state = {
      loaded: false,
      downloaded: false
    };
  }

  downloadFile = async () => {
    try {
      if (await fs.exists(savePath)) {
        const stat = await fs.stat(savePath);
        console.log(stat);
        if (stat.isFile()) {
          this.setState({ downloaded: true});
          return;
        }
      }
      
    } catch(e) {}

    await fs.downloadFile({
      fromUrl: videoURL,
      toFile: savePath,
    }).promise;
    console.log('finish');
    this.setState({ downloaded: true});
  };

  render() {
    const { downloaded, loaded, data } = this.state;
    if (!downloaded) {
      this.downloadFile();
    } else if (!loaded) {
      NativeModules.RNMediaMeta.get(savePath)
        .then(result => {
          this.setState({ loaded: true, data: result });
        })
        .catch(e => console.log(e));
    }
    return (
      <View style={styles.container}>
        {
          (() => {
            if (!downloaded) {
              return <Text style={styles.text}>Downloading...</Text>;
            } else if (!loaded) {
              return <Text style={styles.text}>Loading...</Text>;
            } else {
              if (data && data.thumb) {
                return (
                  <Image
                    style={styles.image}
                    source={{ uri: 'data:image/png;base64,' + data.thumb }}
                  />
                );
              } else {
                return <Text style={styles.text}>No thumb</Text>;
              }
            }
          })()
        }
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  text: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  image: {
    width: 100,
    height: 100,
    resizeMode: 'cover',
    borderWidth: 1,
    borderColor: 'red',
  }
});

AppRegistry.registerComponent('MediaMetaSample', () => MediaMetaSample);

@@ -170,16 +170,65 @@
 ive-fs';
+%0Aimport MediaMeta from 'react-native-media-meta';
 %0A%0Aconst 
@@ -664,35 +664,8 @@
 h);%0A
-        console.log(stat);%0A
     
@@ -685,16 +685,29 @@
 isFile()
+ && stat.size
 ) %7B%0A    
@@ -790,32 +790,8 @@
 %7D%0A  
-    %0A    %7D catch(e) %7B%7D%0A%0A
     
@@ -814,16 +814,18 @@
 dFile(%7B%0A
+  
       fr
@@ -847,16 +847,18 @@
 ,%0A      
+  
 toFile: 
@@ -871,16 +871,18 @@
 th,%0A    
+  
 %7D).promi
@@ -885,24 +885,26 @@
 romise;%0A    
+ 
+ 
 console.log(
@@ -914,16 +914,18 @@
 nish');%0A
+  
     this
@@ -955,16 +955,64 @@
  true%7D);
+ %0A    %7D catch(e) %7B%0A      console.error(e);%0A    %7D
 %0A  %7D;%0A%0A 
@@ -1162,24 +1162,8 @@
     
-NativeModules.RN
 Medi
@@ -1304,19 +1304,21 @@
 console.
-log
+error
 (e));%0A  

Update example