0

I prepared an application, I need to get the video links from the data file. What can I do for that.

source={{ ? }} and How do I project 4 videos to the screen using flatlist? Thank you

export const data = [
   {
   id: 1,
   name: "Video1",
   video: "http://example.com/video1.mp4" -> ***how do i do this***
   },
   {
   id: 2,
   name: "Video2",
   video: "http://example.com/video2.mp4" -> ***how do i do this***
   },
   {
   id: 3,
   name: "Video3",
   video: "http://example.com/video3.mp4" -> ***how do i do this***
   },
];

return (
    <View style={styles.container}>
      <Video
        ref={video}
        style={{ alignSelf: "center", width: 320, height: 200 }}
        source={{ ? }}
        useNativeControls
        resizeMode="contain"
        isLooping
        onPlaybackStatusUpdate={(status) => setStatus(() => status)}
      />

Example Image: I want to have a video code like the code written here :)

export const data = [

{ 
    id: 1, 
    name: "image1", 
    image: "../assets/image/sun.png" 
},
];     

import data from './data';  

function App() { 
    return ( 
      <View>
     <Image  source={data.image}/>
     </View) 
} 

kikirim
  • 37
  • 8

3 Answers3

0

You could use the JavaScript FETCH Api. It is like Jquery but better (I think). It is very easy to fetch a video with this. If you're using a functional component you can use useEffect() to fetch the video when the App is loading (loaded)

Here is an example

fetch('http://example.com/yourvideo.mp4')
  .then(response => response.json())
  .then(data => doSomething());

Now you fetched the video :)

Henrik
  • 828
  • 8
  • 34
0

if you put your json file in android's asset and iOS resource, you can use this package to read the file content https://www.npmjs.com/package/react-native-file-asset

Hai Trinh
  • 1
  • 3
0
return (
    <View style={styles.container}>
      <Video
        ref={video}
        style={{ alignSelf: "center", width: 320, height: 200 }}
        source={{ uri: data?.video }}
        useNativeControls
        resizeMode="contain"
        isLooping
        onPlaybackStatusUpdate={(status) => setStatus(() => status)}
      />

kikirim
  • 37
  • 8