小编sau*_*ere的帖子

React Native如何控制WebView中的播放/暂停视频

我正在尝试通过 React Native 在 WebView 中播放和暂停视频。
但是当 this.state.shouldPlay 变为 true 时,下面注入的 JavaScript 不起作用。

injectedJavaScript=
{`document.getElementsByTagName("video")[0].play();`}
Run Code Online (Sandbox Code Playgroud)

请告知如何从 React Native 控制 WebView 中的视频。
由于性能问题,无法使用react-native-video。

import * as React from 'react';
import { Component, useState, useEffect  } from 'react';
import { Text, View, StyleSheet, Image, TouchableOpacity} from 'react-native';
import {WebView} from 'react-native-webview';

export default class App extends Component {

  constructor(props) {
    super(props);
    this.state = {
      shouldPlay: false, // not play at default
    }
  }

  _handlePlayAndPause = () => {
    if (this.state.shouldPlay == false) …
Run Code Online (Sandbox Code Playgroud)

webview html5-video react-native

5
推荐指数
0
解决办法
1184
查看次数

标签 统计

html5-video ×1

react-native ×1

webview ×1