<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      RN 使用react-native-video 播放視頻(包含進度條、全屏)

      21年12月3日,闡述上有問題:應該將問題拆分,不該將代碼整一大堆,看著很不舒適

       

      目標需求:
      1. 實現視頻播放

      2. 進度條

      3. 進入全屏

      目標圖是這樣的:

       

       

       

      需要三個組件

      1. 播放視頻組件, react-native-video    官網地址 https://www.npmjs.com/package/react-native-video#allowsexternalplayback

      2. 進度條,官網上提供的 slider組件我忘記說的什么原因,即將停止支持,我找了react-native-silder  這個個第三方包 官網地址  https://github.com/react-native-community/react-native-slider#onvaluechange
      現在react-native-silder 的一些生命周期方法都是警告,因為react很多聲明周期函數,已經廢棄或改名字 ,我目前在嘗試   https://github.com/callstack/react-native-slider

      3. 全屏播放,react-native-orientation這個包有問題,因為RN 將對 rnpm 換一種支持策略 ,所以選擇用 react-native-orientation-locker 官網地址  https://github.com/wonday/react-native-orientation-locker

       

      后面的就直接上代碼了

      import React from 'react';
      import {View,Text,StyleSheet,TouchableWithoutFeedback,TouchableOpacity,Dimensions} from 'react-native';
      //導入Video組件
      import Video from 'react-native-video';
      // 導入 Silder組件
      import Slider from '@react-native-community/slider';
      // 屏幕方向鎖定: 他需要改變 原來Android文件代碼,當然適配兩端的話,IOS也是需要更改的。
      import Orientation from 'react-native-orientation-locker';
      
      let screenWidth  = Dimensions.get('window').width;
      let screenHeight = Dimensions.get('window').height;
      console.log(screenWidth+"   "+screenHeight+"帶有小數");
      
      export default class App extends React.Component{
          constructor(props){
              super(props);
              this.changePausedState   = this.changePausedState.bind(this);
              this.customerSliderValue = this.customerSliderValue.bind(this);
              this.enterFullScreen     = this.enterFullScreen.bind(this);
              this._changePauseSliderFullState = this._changePauseSliderFullState.bind(this);
              this._onStartShouldSetResponder = this._onStartShouldSetResponder.bind(this);
              this.state = {          
                  isPaused: true,  //是暫停
                  duration: 0,      //總時長
                  currentTime: 0, //當前播放時間
                  sliderValue: 0,   //進度條的進度 
      
                  //用來控制進入全屏的屬性
                  videoWidth: screenWidth,
                  videoHeight: 226,
                  isFullScreen: false,
                  isVisiblePausedSliderFullScreen: false
              }
          }
          changePausedState(){ //控制按鈕顯示播放,要顯示進度條3秒鐘,之后關閉顯示
              this.setState({
                  isPaused: this.state.isPaused?false:true,
                  isVisiblePausedSliderFullScreen: true
              })
              //這個定時調用失去了this指向
              let that = this;
              setTimeout(function(){
                  that.setState({
                      isVisiblePausedSliderFullScreen: false
                  })
              },3000)
          }
          _changePauseSliderFullState(){ // 單擊事件,是否顯示 “暫停、進度條、全屏按鈕 盒子”
              let flag = this.state.isVisiblePausedSliderFullScreen?false:true; 
              this.setState({
                  isVisiblePausedSliderFullScreen: flag
              })
               //這個定時調用失去了this指向
               let that = this;
               setTimeout(function(){
                   that.setState({
                       isVisiblePausedSliderFullScreen: false
                   })
               },3000)
          } 
           //格式化音樂播放的時間為0:00。借助onProgress的定時器調用,更新當前時間
          formatMediaTime(time) {
              let minute = Math.floor(time / 60);
              let second = parseInt(time - minute * 60);
              minute = minute >= 10 ? minute : "0" + minute;
              second = second >= 10 ? second : "0" + second;
              return minute + ":" + second;
             
          }
          //加載視頻調用,主要是拿到 “總時間”,并格式化
          customerOnload(e){
              let time = e.duration;   
              this.setState({
                  duration: time
              })
          }
          // 獲得當前的,播放時間數,但這個數是0.104,需要處理
          customerOnprogress(e){
              let time = e.currentTime;   // 獲取播放視頻的秒數       
              this.setState({
                  currentTime: time,
                  sliderValue: time
              })           
          }
          // 移動滑塊,改變視頻播放進度
          customerSliderValue(value){  
              this.player.seek(value);    
          }
          enterFullScreen(){ //1.改變寬高  2.允許進入全屏模式  3.如何配置屏幕旋轉,不需要改變進度條盒子的顯示和隱藏
              this.setState({
                  videoWidth: screenHeight,
                  videoHeight: screenWidth,
                  isFullScreen: true
              })
              // 直接設置方向
              Orientation.lockToLandscape();
          }
          _onStartShouldSetResponder(e){
              console.log(e);
          }
          componentDidMount() {
              var initial = Orientation.getInitialOrientation();
              if (initial === 'PORTRAIT') {
               console.log('是豎屏');
              } else {
                  console.log('如果是橫屏,就將其旋轉過來');
                  Orientation.lockToPortrait();
              }
          }
          render(){
              // 播放按鈕組件:是否顯示
              let playButtonComponent = (
                  <TouchableWithoutFeedback
                      onPress={this.changePausedState}
                  >
                      <View style={styles.playBtn}>                       
                      </View> 
                  </TouchableWithoutFeedback>
              );
              let pausedBtn = this.state.isPaused?playButtonComponent:null;
              // 暫停按鈕、進度條、全屏按鈕 是否顯示
              let pausedSliderFullComponent = (
                  <View style={{position:"absolute",bottom:0}}>
                      <View style={{flexDirection:'row',alignItems:'center'}}>
                          {/* 進度條按鈕     */}
                          <View style={styles.sliderBox}>
                              <Text>{this.formatMediaTime(this.state.currentTime)}</Text>
                              <Slider 
                                  style={{width: 200, height: 40}} 
                                  value={this.state.sliderValue}
                                  maximumValue={this.state.duration}
                                  thumbTintColor="#000" //開關夾點的yanse              
                                  minimumTrackTintColor="red"
                                  maximumTrackTintColor="#ccc"
                                  step={1}
                                  onValueChange={this.customerSliderValue}
                              />
                              <Text>{this.formatMediaTime(this.state.duration)}</Text>
                          </View>
                          {/* 全屏按鈕 */}
                          <View>
                              <TouchableOpacity
                                  onPress={this.enterFullScreen}
                              >                           
                                  <Text style={{backgroundColor:'#00ff00',padding:5}}>全屏</Text>                      
                              </TouchableOpacity> 
                          </View>
                      
                  
                      </View>   
                  </View>
              );
              let pausedSliderFull = this.state.isVisiblePausedSliderFullScreen?pausedSliderFullComponent:null;
              return (
                  <View>
                      <View>
                          <TouchableWithoutFeedback
                              onPress={this._changePauseSliderFullState}
                              onResponderMove={this._onStartShouldSetResponder}
                          >  
                              <Video source={require('../jifen.mp4')}
                                  ref={(ref) => {
                                      this.player = ref
                                  }}  
                                  style={{width: this.state.videoWidth,height: this.state.videoHeight,backgroundColor:"#FFC1C1"}}
                                  allowsExternalPlayback={false} // 不允許導出 或 其他播放器播放
                                  paused = {this.state.isPaused} // 控制視頻是否播放
                                  resizeMode="cover"
                                  onLoad={(e)=>this.customerOnload(e)} 
                                  onProgress={(e)=>this.customerOnprogress(e)}                       
                                  fullscreen={this.state.isFullScreen}
                              />
                          </TouchableWithoutFeedback> 
                          {/* 播放的按鈕:點擊之后需要消失 */}
                          {pausedBtn}
                          {/* 暫停按鈕,進度條,全屏按鈕 */}
                          {pausedSliderFull}
                      </View>
      </View>
              )
          }
      }
      var styles = StyleSheet.create({
          myVideo:{
              width: 340,
              height: 240
          },
          playBtn:{
              width: 50,
              height: 50,
              backgroundColor:'red',
              borderRadius: 50,
              position: "absolute",
              top: "50%",
              left: "50%",
              marginLeft: -25,
              marginTop:-25,
              zIndex:999
          },
          sliderBox:{
              flex:0,
              flexDirection:'row',
              alignItems:'center'
          }
        });



      看個效果圖吧,這個普通播放時



      這是全屏播放時

       

       

      測試這個花了挺長時間的,有用點個贊吧,哈哈

       

      posted @ 2019-12-12 17:56  tengyuxin  閱讀(13275)  評論(5)    收藏  舉報
      主站蜘蛛池模板: 精品不卡一区二区三区| 欧美不卡无线在线一二三区观| 国产av一区二区三区综合| 好吊视频一区二区三区人妖| 日韩乱码人妻无码中文字幕| 亚洲国产天堂久久综合226114 | 久久亚洲精品11p| 中文字幕在线无码一区二区三区| 亚洲国产成人AⅤ毛片奶水 | av在线播放观看国产| 日韩在线视频网| 亚洲A综合一区二区三区| 国产乱子伦精品免费女| 国产人免费人成免费视频| 日韩精品一区二区三区在线观看| 国产偷国产偷亚洲高清午夜| 在线精品国精品国产尤物| 精品国产乱子伦一区二区三区| 精品亚洲女同一区二区| 制服丝袜另类专区制服| 日本熟妇人妻一区二区三区| 精品国产成人一区二区| 自偷自拍亚洲综合精品| 国产一区二区三区九九视频| 日韩亚洲国产综合高清| 国产对白老熟女正在播放| 精品国产这么小也不放过| 日韩无码视频网站| www久久只有这里有精品| 亚洲高潮喷水无码AV电影| 国产MD视频一区二区三区 | 天堂中文最新版在线官网在线| 亚洲日本欧美日韩中文字幕| 久久综合九色综合欧洲98| 国产成人综合色就色综合| 国产免费午夜福利在线播放| 精品 日韩 国产 欧美 视频| 亚洲精品国产av成拍色拍个| 久久夜色精品国产噜噜亚洲sv| 无码av波多野结衣 | 成在线人免费视频|