|
@@ -26,6 +26,7 @@ export default class CusVideo extends React.Component {
|
|
|
super(props);
|
|
|
this.pressStatus = false;
|
|
|
this.progress = 0;
|
|
|
+ this.time_hideController;
|
|
|
}
|
|
|
config = {
|
|
|
changeX: 0,
|
|
@@ -42,12 +43,35 @@ export default class CusVideo extends React.Component {
|
|
|
resizeMode: "stretch",
|
|
|
duration: 0.0,
|
|
|
currentTime: 0.0,
|
|
|
- paused: false,
|
|
|
+ paused: true,
|
|
|
+ onBuffer: true,
|
|
|
wheel: false,
|
|
|
isFull: false,
|
|
|
needback: this.props.needback,
|
|
|
show_controller: true,
|
|
|
- show_loading: true
|
|
|
+ show_loading: true,
|
|
|
+ loading_arr: [
|
|
|
+ require("../images/video/loading1.png"),
|
|
|
+ require("../images/video/loading2.png"),
|
|
|
+ require("../images/video/loading3.png"),
|
|
|
+ require("../images/video/loading4.png"),
|
|
|
+ require("../images/video/loading5.png"),
|
|
|
+ require("../images/video/loading6.png"),
|
|
|
+ require("../images/video/loading7.png"),
|
|
|
+ require("../images/video/loading8.png"),
|
|
|
+ require("../images/video/loading9.png"),
|
|
|
+ require("../images/video/loading10.png"),
|
|
|
+ require("../images/video/loading11.png"),
|
|
|
+ require("../images/video/loading12.png"),
|
|
|
+ require("../images/video/loading13.png"),
|
|
|
+ require("../images/video/loading14.png"),
|
|
|
+ require("../images/video/loading15.png"),
|
|
|
+ require("../images/video/loading16.png"),
|
|
|
+ require("../images/video/loading17.png"),
|
|
|
+ require("../images/video/loading18.png"),
|
|
|
+ require("../images/video/loading19.png"),
|
|
|
+ require("../images/video/loading20.png")
|
|
|
+ ]
|
|
|
};
|
|
|
|
|
|
render() {
|
|
@@ -77,11 +101,11 @@ export default class CusVideo extends React.Component {
|
|
|
onLoadStart={this.loadStart} // 当视频开始加载时的回调函数
|
|
|
onLoad={this.onLoad} //加载媒体并准备播放时调用的回调函数。
|
|
|
onProgress={this.onProgress} //视频播放过程中每个间隔进度单位调用的回调函数
|
|
|
- onEnd={this.onEnd} //视频播放结束时的回调函数
|
|
|
onAudioBecomingNoisy={this.onAudioBecomingNoisy} //音频变得嘈杂时的回调 - 应暂停视频
|
|
|
onAudioFocusChanged={this.onAudioFocusChanged} //音频焦点丢失时的回调 - 如果焦点丢失则暂停
|
|
|
repeat={this.state.wheel} //确定在到达结尾时是否重复播放视频。
|
|
|
- onError={this.onError} // 当视频不能加载,或出错后的回调函数
|
|
|
+ onError={this.onError.bind(this)} // 当视频不能加载,或出错后的回调函数
|
|
|
+ onEnd={this.onEnd.bind(this)} //视频播放结束时的回调函数
|
|
|
playInBackground={false} // 当app转到后台运行的时候,播放是否暂停
|
|
|
playWhenInactive={true} // [iOS] Video continues to play when control or notification center are shown. 仅适用于IOS
|
|
|
/>
|
|
@@ -94,7 +118,10 @@ export default class CusVideo extends React.Component {
|
|
|
justifyContent: "center"
|
|
|
}}
|
|
|
>
|
|
|
- <Loading show={this.state.show_loading} />
|
|
|
+ <Loading
|
|
|
+ loading_arr={this.state.loading_arr}
|
|
|
+ show={this.state.show_loading}
|
|
|
+ />
|
|
|
</View>
|
|
|
<TopController
|
|
|
ref={view => (this.topcontroller = view)}
|
|
@@ -121,7 +148,6 @@ export default class CusVideo extends React.Component {
|
|
|
onStartShouldSetPanResponderCapture: (evt, gestureState) => true,
|
|
|
onMoveShouldSetPanResponder: (evt, gestureState) => true,
|
|
|
onMoveShouldSetPanResponderCapture: (evt, gestureState) => true,
|
|
|
-
|
|
|
onPanResponderGrant: (evt, gestureState) => {
|
|
|
this.pressStatus = true;
|
|
|
this.config.changeY = evt.nativeEvent.pageY;
|
|
@@ -131,11 +157,9 @@ export default class CusVideo extends React.Component {
|
|
|
} else {
|
|
|
this.showController();
|
|
|
}
|
|
|
- console.log("onPanResponderGrant");
|
|
|
},
|
|
|
onPanResponderStart: (evt, gestureState) => {
|
|
|
this.pressStatus = true;
|
|
|
- console.log("onPanResponderStart");
|
|
|
},
|
|
|
onPanResponderMove: (evt, gestureState) => {
|
|
|
this.config.yDiff = evt.nativeEvent.pageY - this.config.changeY;
|
|
@@ -145,7 +169,6 @@ export default class CusVideo extends React.Component {
|
|
|
},
|
|
|
onPanResponderEnd: (evt, gestureState) => {
|
|
|
this.pressStatus = true;
|
|
|
- console.log("onPanResponderEnd");
|
|
|
},
|
|
|
onPanResponderTerminationRequest: (evt, gestureState) => true,
|
|
|
onPanResponderRelease: (evt, gestureState) => {
|
|
@@ -172,9 +195,15 @@ export default class CusVideo extends React.Component {
|
|
|
onBuffer({ isBuffering }: { isBuffering: boolean }) {
|
|
|
//true为正在加载,false为没有加载,此处给loading提示
|
|
|
this.setState({
|
|
|
+ onBuffer: isBuffering,
|
|
|
show_loading: isBuffering
|
|
|
});
|
|
|
- console.log("isBuffering:" + isBuffering);
|
|
|
+ }
|
|
|
+ isPlaying() {
|
|
|
+ if (this.state.onBuffer == false && this.state.paused == false) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
onLoad = data => {
|
|
|
//获取的是秒数
|
|
@@ -192,10 +221,16 @@ export default class CusVideo extends React.Component {
|
|
|
};
|
|
|
|
|
|
onError() {
|
|
|
- alert("播放器异常");
|
|
|
+ if (this.props.onEnd == undefined) {
|
|
|
+ } else {
|
|
|
+ this.props.onError();
|
|
|
+ }
|
|
|
}
|
|
|
onEnd() {
|
|
|
- alert("播放结束");
|
|
|
+ if (this.props.onEnd == undefined) {
|
|
|
+ } else {
|
|
|
+ this.props.onEnd();
|
|
|
+ }
|
|
|
}
|
|
|
play() {
|
|
|
//controller的play点击无法换图...
|
|
@@ -218,6 +253,16 @@ export default class CusVideo extends React.Component {
|
|
|
player_status_icon: require("../images/video/pause.png")
|
|
|
});
|
|
|
this.player_icon_index = 0;
|
|
|
+ if (this.state.show_controller) {
|
|
|
+ this.time_hideController = setTimeout(() => {
|
|
|
+ this.setState({
|
|
|
+ show_controller: false
|
|
|
+ // needback: false
|
|
|
+ });
|
|
|
+ this.bottomcontroller.setBottom(-50);
|
|
|
+ this.topcontroller.setTop(-50);
|
|
|
+ }, 5000);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
seekTo(progress) {
|
|
@@ -252,6 +297,7 @@ export default class CusVideo extends React.Component {
|
|
|
duration: 0,
|
|
|
currentTime: 0
|
|
|
});
|
|
|
+ this.bottomcontroller.setProgress(0);
|
|
|
}
|
|
|
|
|
|
videoBackClick() {
|
|
@@ -265,12 +311,22 @@ export default class CusVideo extends React.Component {
|
|
|
}
|
|
|
}
|
|
|
showController() {
|
|
|
+ clearTimeout(this.time_hideController);
|
|
|
this.setState({
|
|
|
show_controller: true
|
|
|
// needback: this.props.needback
|
|
|
});
|
|
|
this.bottomcontroller.setBottom(0);
|
|
|
+ this.bottomcontroller.setProgress(this.state.currentTime);
|
|
|
this.topcontroller.setTop(0);
|
|
|
+ this.time_hideController = setTimeout(() => {
|
|
|
+ this.setState({
|
|
|
+ show_controller: false
|
|
|
+ // needback: false
|
|
|
+ });
|
|
|
+ this.bottomcontroller.setBottom(-50);
|
|
|
+ this.topcontroller.setTop(-50);
|
|
|
+ }, 5000);
|
|
|
}
|
|
|
hideController() {
|
|
|
this.setState({
|
|
@@ -361,44 +417,42 @@ class TopController extends Component {
|
|
|
}
|
|
|
|
|
|
class Loading extends Component {
|
|
|
+ constructor(props) {
|
|
|
+ super(props);
|
|
|
+ this.loading_index = 0;
|
|
|
+ }
|
|
|
state = {
|
|
|
- image_arr: [
|
|
|
- require("../images/video/loading1.png"),
|
|
|
- require("../images/video/loading2.png"),
|
|
|
- require("../images/video/loading3.png"),
|
|
|
- require("../images/video/loading3.png"),
|
|
|
- require("../images/video/loading4.png"),
|
|
|
- require("../images/video/loading5.png"),
|
|
|
- require("../images/video/loading6.png"),
|
|
|
- require("../images/video/loading7.png"),
|
|
|
- require("../images/video/loading8.png"),
|
|
|
- require("../images/video/loading9.png"),
|
|
|
- require("../images/video/loading10.png"),
|
|
|
- require("../images/video/loading11.png"),
|
|
|
- require("../images/video/loading12.png"),
|
|
|
- require("../images/video/loading13.png"),
|
|
|
- require("../images/video/loading14.png"),
|
|
|
- require("../images/video/loading15.png"),
|
|
|
- require("../images/video/loading16.png"),
|
|
|
- require("../images/video/loading17.png"),
|
|
|
- require("../images/video/loading18.png"),
|
|
|
- require("../images/video/loading19.png"),
|
|
|
- require("../images/video/loading20.png")
|
|
|
- ],
|
|
|
- loading_index: 0
|
|
|
+ loading_img: this.props.loading_arr[0]
|
|
|
};
|
|
|
render() {
|
|
|
if (this.props.show) {
|
|
|
return (
|
|
|
<Image
|
|
|
- source={this.state.image_arr[this.state.loading_index]}
|
|
|
- style={{ width: "20%", height: "10%", backgroundColor: "blue" }}
|
|
|
+ source={this.state.loading_img}
|
|
|
+ style={{ width: 100, height: 20 }}
|
|
|
/>
|
|
|
);
|
|
|
} else {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
+ componentWillMount() {
|
|
|
+ this.changeIndex();
|
|
|
+ }
|
|
|
+
|
|
|
+ changeIndex() {
|
|
|
+ setTimeout(() => {
|
|
|
+ if (this.loading_index > this.props.loading_arr.length - 2) {
|
|
|
+ this.loading_index = 0;
|
|
|
+ } else {
|
|
|
+ this.loading_index = this.loading_index + 1;
|
|
|
+ }
|
|
|
+ this.setState({
|
|
|
+ loading_img: this.props.loading_arr[this.loading_index]
|
|
|
+ });
|
|
|
+ this.changeIndex();
|
|
|
+ }, 1);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
class BottomController extends Component {
|
|
@@ -537,18 +591,22 @@ const styles = StyleSheet.create({
|
|
|
|
|
|
/**
|
|
|
使用方法
|
|
|
- <CusVideo
|
|
|
- uri={this.state.video_uri}
|
|
|
- ref={view => (this.video = view)}
|
|
|
- needback={true} //(是否需要小窗口的返回按钮)
|
|
|
- videoback={this.clickVideoBack.bind(this)}//(小窗口返回按钮的事件)
|
|
|
- videofullScreenPlayer={this.fullScreenPlayer.bind(this)}//(点击全屏按钮的事件)
|
|
|
- style={{
|
|
|
- flex: this.state.video_flex,
|
|
|
- width: this.state.video_width,
|
|
|
- height: this.state.video_height
|
|
|
- }}
|
|
|
- />
|
|
|
+ <CusVideo
|
|
|
+ show={this.state.video_show} //是否显示
|
|
|
+ uri={this.state.video_uri} //播放路径
|
|
|
+ ref={view => (this.video = view)} //设置ID
|
|
|
+ needback={false}
|
|
|
+ videoback={() => alert("videoback")}
|
|
|
+ videofullScreenPlayer={this.fullScreenPlayer.bind(this)}
|
|
|
+ style={{
|
|
|
+ left: this.state.x,
|
|
|
+ top: this.state.y,
|
|
|
+ width: this.state.video_width,
|
|
|
+ height: this.state.video_height,
|
|
|
+ overflow: "hidden",
|
|
|
+ position: "absolute"
|
|
|
+ }}
|
|
|
+ />
|
|
|
|
|
|
|
|
|
*/
|