【问题标题】:Unable to play two videos side by side in separate containers, how can I fix this? When I comment out one video, the other appears and plays无法在单独的容器中并排播放两个视频,我该如何解决?当我注释掉一个视频时,另一个会出现并播放
【发布时间】:2021-12-08 15:12:34
【问题描述】:

此代码将呈现到我的帖子页面,这是下一个代码块

import React from "react";
import { View } from "react-native";
import Post from "../../components/Post";

const Home = () => {
  return (
    <View>
      <Post />
    </View>
  );
};

export default Home;

此代码是发布页面,我必须在其中注释掉一个视频才能播放另一个视频。当我取消注释两个视频时,仅播放顶部的视频(leftContainer)

import React from "react";
import { View } from "react-native";
import Video from "react-native-video";
import styles from "./styles";

const Post = () => {
  return (
    <View>
      {/* <View style={styles.leftContainer}>
            <Video
            source={{uri: 'https://static.videezy.com/system/resources/previews/000/008/292/original/Young_African_American_Woman_Headphones_2.mp4'}}
            style={styles.video}
            resizeMode={'cover'}/>
        </View> */}

      <View style={styles.rightContainer}>
        <Video
          source={{
            uri: "https://static.videezy.com/system/resources/previews/000/008/444/original/Dark_Haired_Girl_in_deep_thought_1.mp4",
          }}
          style={styles.video}
          resizeMode={"cover"}
        />
      </View>
    </View>
  );
};

export default Post;

这是我为每个视频分别设置了 leftContainer 和 rightContainer 的样式表:

import { StyleSheet, Dimensions } from "react-native";

const styles = StyleSheet.create({
  leftContainer: {
    width: "50%",
    height: Dimensions.get("window").height,
    flexDirection: "row",
  },
  rightContainer: {
    width: "50%",
    height: Dimensions.get("window").height,
    flexDirection: "row",
    marginLeft: "50%",
  },
  video: {
    position: "absolute",
    top: 0,
    left: 0,
    bottom: 0,
    right: 0,
    flexDirection: "row",
  },
});

export default styles;

【问题讨论】:

    标签: react-native react-native-video


    【解决方案1】:
    videoContainer: {
        flexDirection: 'row',
    },
    leftContainer: {
        width:'50%',
        height: Dimensions.get('window').height,
        flex: 1,
    },
    rightContainer: {
        width:'50%',
        height: Dimensions.get('window').height,
        flex: 1,
    },
    

    【讨论】:

      猜你喜欢
      • 2016-08-02
      • 2019-02-03
      • 1970-01-01
      • 2021-09-26
      • 2019-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多