首页 > 解决方案 > 当列表更新时,React Native Video 从暂停状态播放

问题描述

我有一个视频播放器,其下方有一个视频缩略图列表,并且我正在调整分页以更新该列表。当新视频添加到我的状态并且视频暂停时,组件会重新渲染,并且由于默认设置了自动播放,因此视频会从暂停状态播放。

我尝试使用 shouldComponentUpdate 并手动尝试管理某些状态作为解决方法,但无济于事。

            <VideoPlayer
              navigator={this.props.navigator}
              toggleResizeModeOnFullscreen={false}
              repeat
              disableFullscreen
              ignoreSilentSwitch="ignore"
              disableVolume
              ref={ref => {
                this.videoPlayer = ref;
              }}
              source={{ uri: downloadUrl }}
              rate={1.0}
              volume={1.0}
              resizeMode="contain"
              style={styles.video}
              onEnd={this.playNextShortShift}
              onVideoError={this.onVideoError}
            />
          </View>
          {this.state.orientation === 'portrait' && (
            <View style={{ flex: 1 }}>
              <View style={styles.videoPlayerTextContainer}>
                <View style={{ height: 12 }} />
                <Text style={styles.videoTitleText}>NOW PLAYING:</Text>
                <View style={{ height: 4 }} />
                <Text style={styles.videoTitleText}>{title}</Text>
              </View>
              <FlatList
                ref={flatList => {
                  this.flatList = flatList;
                }}
                bounces={false}
                style={{ flex: 0 }}
                getItemLayout={this.getItemLayout}
                horizontal={false}
                data={data}
                initialNumToRender={data.length}
                extraData={this.state}
                renderItem={({ item, index }) => this.renderEntry(item, index)}
                keyExtractor={(item, index) => index}
                onEndReached={this.handleLoadMore}
                onEndReachedThreshold={0.5}
                onMomentumScrollBegin={() => {
                  this.onEndReachedCalledDuringMomentum = false;
                }}
              />
            </View>```

How can update the thumbnail list and maintain the same video player state? Specifically when paused.

Thanks!

标签: react-nativereact-native-video

解决方案


推荐阅读