我正在尝试通过 React Native 在 WebView 中播放和暂停视频。
但是当 this.state.shouldPlay 变为 true 时,下面注入的 JavaScript 不起作用。
Run Code Online (Sandbox Code Playgroud)injectedJavaScript= {`document.getElementsByTagName("video")[0].play();`}
请告知如何从 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)