'How to use an absolute path for a local video on the device when using react-native-video?
I'm developing an App that should automatically play a video stored on a specific path of the device (currently, i'm trying to access the DCIM folder) without any user interaction needed.
The react-native-video documentation states that I can do something like this "source={{ uri: 'file:///sdcard/Movies/sintel.mp4' }}", I'm already using the needed permission 'android.permission.READ_EXTERNAL_STORAGE' but i can't make it work.
I'm always tracking the paths I test with the RNFS library, and the output says that the file does exist.
Here is my code:
import React, { useEffect } from 'react';
import Video from 'react-native-video';
import { StyleSheet, View } from 'react-native';
import ImmersiveMode from 'react-native-immersive-mode';
var RNFS = require('react-native-fs');
async function fileExist(path) {
let exists = await RNFS.exists(path);
return exists; //This one returns true
}
export default function App() {
useEffect(() => {
fileExist('file:///storage/emulated/0/DCIM/video/video.m4v')
.then((result) => console.log('Path exists:', result));
ImmersiveMode.fullLayout(true);
ImmersiveMode.setBarMode('BottomSticky');
return () => {
ImmersiveMode.fullLayout(false);
ImmersiveMode.setBarMode('Normal');
}
}, []);
return (
<View style = { styles.background }>
<Video style = { styles.video }
volume = { 1.0 }
play = {true}
replay = {true}
muted = { false }
resizeMode = { 'stretch' }
source = {{ uri: 'file:///storage/emulated/0/DCIM/video/video.m4v' }}/>
</View>
);
}
Notes:
I already tried an online video and it plays just fine: source = {{ uri: 'https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_1920_18MG.mp4' }}
A file inside the project also works fine: source = { require('./video/video.m4v') }
I also tried a path from the SD card, this one doesn't work: source = {{ uri: 'file:///sdcard/DCIM/video/video.m4v' }}
Am I doing something wrong? is this a bug or something like that? I really appreciate your help.
Solution 1:[1]
bro try removing file:// from the uri string
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Rahul Negi |