javascript - React-Native-Web 的视频支持

标签 javascript react-native react-native-web react-native-video

有没有在 React-Native-Web 中播放视频的解决方案

React-Native-Web:https://github.com/necolas/react-native-web

react 原生视频:https://github.com/react-native-community/react-native-video

最佳答案

我不知道这个解决方案有多可行,但由于你的目标是网络,你可以使用和滥用 createElement来自 react-native-web创建视频元素。

例如,您可以像这样创建一个无状态组件:

import { createElement } from "react-native-web";

const Video = (props) => {
  const attrs = {
    src: props.source,
    poster: props.poster,
    controls: "controls"
  }
  return createElement("video", attrs)
}
export default Video

然后像这样在您的应用程序中使用它:
<Video
  source={require("./stock_video.mp4")}
  poster={'https://www.fillmurray.com/480/300'}
/>

这里有一点demo它是如何工作的。

关于javascript - React-Native-Web 的视频支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59318412/

相关文章:

react-native - react native FlatList警告

react-native - 网络上的导航 react-navigation

javascript - ReactJS/JavaScript : Not receiving resize event for many cases

javascript - 为函数内的 else 语句创建循环

javascript - jQuery 日期/时间选择器

react-native - 无法解析模块 'react-native-screen'

javascript - 如何使用 AsyncStorage 在 React Native 中保存登录凭据?

react-native - React Native Web - 控制 View 生成的 html 标签?

c# - 从 Javascript 设置 Viewstate 的值

javascript - 以编程方式检查网络资源是否已加载到网页