Как воспроизвести список видео последовательно по умолчанию, не нажимая кнопку «Далее», чтобы получить доступ из локальных файлов устройства, используя реагировать родной - PullRequest
0 голосов
/ 27 марта 2020
const filePath = `${dirs.DownloadDir}/samplevideos/1.mp4`;
const filePath1 = `${dirs.DownloadDir}/samplevideos/2.mp4`;
const paths = [{path:filePath},{path:filePath1}]

 {paths&&paths.map((data,inx)=>{
      return  <Video key={inx} source={{uri:data.path }}
                     volume={50}
                     resizeMode="cover"
                     style={styles.videoStyle}
              />
    })}

Я пробовал это, но проигрывал только последнее видео. Любая помощь будет оценена.

samplevideos folder

1 Ответ

0 голосов
/ 01 апреля 2020

Я нашел решение для этого вопроса, поэтому публикация здесь может помочь кому-то в будущем.

существует обратный вызов onEnd, доступный в реагирующем видео, основанный на этом увеличивающемся индексе следующего видео

import React,{useEffect,useState} from 'react';
import {
  StyleSheet,
  View,
  Image,
  Text,
  Dimensions,
  PermissionsAndroid
} from 'react-native';

import Video from 'react-native-video';
import RNFetchBlob from 'rn-fetch-blob';

const FILE_PATHS = `${RNFetchBlob.fs.dirs.DownloadDir}/samplevideos/`;

const App = () => {

  const [videoPaths,setVideosPath] = useState([]);
  const [inxofCurrentVideo,setVideoIndex] = useState(0);

  useEffect(() => {
    PermissionsAndroid.RESULTS.GRANTED;
    getVideoPaths();
  },[])


  const getVideoPaths = ()=>{
    RNFetchBlob.fs.ls(FILE_PATHS).then(files => {
      setVideosPath(files);
    }).catch(error => console.log(error))
  };
      const onEnd =()=> {
    if((inxofCurrentVideo < videoPaths.length) || (videoPaths.length === inxofCurrentVideo)){
      setVideoIndex(inxofCurrentVideo+1);
    }
  }

  return (
    <View style={styles.videoContainer}>
      <View style={styles.row}>
      {videoPaths.length>0&&<Video onEnd = {onEnd}
        source={{uri:(FILE_PATHS + videoPaths[inxofCurrentVideo])}}
        volume={50}
        resizeMode="cover"
        style={styles.videoStyle}
       /> }      
      </View>

    </View>
  );
};

const styles = StyleSheet.create({
  videoContainer: {
    flex: 1,

   // backgroundColor: 'black',
  },
  row: {
    flex: 1,
    flexDirection: "row",
    width: '100%'
  },
  col6: {
    width: "50%"
  },
videoStyle: {
    position: 'absolute',
    top: 0,
    bottom: 5,
    left: 0,
    right: 0,
},
});

export default App;
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...