|
@@ -11,6 +11,7 @@ import {
|
|
|
} from "react-native";
|
|
|
import { createStackNavigator, createAppContainer } from "react-navigation";
|
|
|
import Video from "react-native-video";
|
|
|
+import SeekBar from "../components/SeekBar";
|
|
|
const instructions = Platform.select({
|
|
|
ios: "Press Cmd+R to reload,\n" + "Cmd+D or shake for dev menu",
|
|
|
android:
|
|
@@ -28,7 +29,10 @@ export default class CusVideo extends React.Component {
|
|
|
duration: 0.0,
|
|
|
currentTime: 0.0,
|
|
|
paused: false,
|
|
|
- wheel: false
|
|
|
+ wheel: false,
|
|
|
+ player_status_icon: require("../images/video/start.png"),
|
|
|
+ isFull: false,
|
|
|
+ needback: this.props.needback
|
|
|
};
|
|
|
|
|
|
render() {
|
|
@@ -45,6 +49,7 @@ export default class CusVideo extends React.Component {
|
|
|
// poster={this.props.poster}
|
|
|
resizeMode={this.state.resizeMode}
|
|
|
// posterResizeMode={this.state.resizeMode}
|
|
|
+ onBuffer={this.onBuffer}
|
|
|
rate={this.state.rate} //播放速率
|
|
|
paused={this.state.paused} //暂停
|
|
|
volume={this.state.volume} //调节音量
|
|
@@ -61,6 +66,42 @@ export default class CusVideo extends React.Component {
|
|
|
playInBackground={false} // 当app转到后台运行的时候,播放是否暂停
|
|
|
playWhenInactive={true} // [iOS] Video continues to play when control or notification center are shown. 仅适用于IOS
|
|
|
/>
|
|
|
+ <View
|
|
|
+ style={{
|
|
|
+ flexDirection: "row",
|
|
|
+ position: "absolute",
|
|
|
+ width: "100%",
|
|
|
+ height: 50,
|
|
|
+ alignItems: "center",
|
|
|
+ justifyContent: "center"
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <View
|
|
|
+ style={{
|
|
|
+ flex: 1,
|
|
|
+ alignItems: "center"
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <VideoBack
|
|
|
+ needback={this.state.needback}
|
|
|
+ videoback={this.videoBackClick.bind(this)}
|
|
|
+ />
|
|
|
+ </View>
|
|
|
+ <View style={{ flex: 2 }} />
|
|
|
+ <View
|
|
|
+ style={{
|
|
|
+ flex: 9,
|
|
|
+ overflow: "hidden"
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ <View style={{ flex: 2 }} />
|
|
|
+ <View
|
|
|
+ style={{
|
|
|
+ flex: 1,
|
|
|
+ alignItems: "center"
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ </View>
|
|
|
<View style={[styles.player_controller]}>
|
|
|
<View
|
|
|
style={{
|
|
@@ -80,11 +121,11 @@ export default class CusVideo extends React.Component {
|
|
|
>
|
|
|
<Image
|
|
|
style={[styles.player_pause_icon]}
|
|
|
- //source={require("../imgs/player_image_state_pause.png")}
|
|
|
+ source={this.state.player_status_icon}
|
|
|
/>
|
|
|
</TouchableOpacity>
|
|
|
</View>
|
|
|
- <View style={{ flex: 3 }}>
|
|
|
+ <View style={{ flex: 2 }}>
|
|
|
{/* //左侧当前播放时长 */}
|
|
|
<Text style={[styles.player_time]}>
|
|
|
{formatTime(this.state.currentTime)}
|
|
@@ -92,37 +133,45 @@ export default class CusVideo extends React.Component {
|
|
|
</View>
|
|
|
<View
|
|
|
style={{
|
|
|
- flex: 7,
|
|
|
- backgroundColor: "yellow"
|
|
|
+ flex: 9,
|
|
|
+ overflow: "hidden"
|
|
|
}}
|
|
|
>
|
|
|
{/* //中间进度条 */}
|
|
|
- {/* <SeekBar
|
|
|
- style={{
|
|
|
- flex: 1,
|
|
|
- alignItems: "center",
|
|
|
- justifyContent: "center",
|
|
|
- width: "100%"
|
|
|
- }}
|
|
|
- max={this.state.duration}
|
|
|
- progress={this.state.currentTime}
|
|
|
- /> */}
|
|
|
+ <SeekBar
|
|
|
+ style={{ flex: 1 }}
|
|
|
+ ref={view => (this.seekbar = view)}
|
|
|
+ //必须带此方法,作为滑动之后抬起的回调
|
|
|
+ touchUpCallBack={this.touch_up_callback.bind(this)}
|
|
|
+ />
|
|
|
</View>
|
|
|
- <View style={{ flex: 3 }}>
|
|
|
+ <View style={{ flex: 2 }}>
|
|
|
{/* //右侧总时长 */}
|
|
|
<Text style={[styles.player_time]}>
|
|
|
{formatTime(this.state.duration)}
|
|
|
</Text>
|
|
|
</View>
|
|
|
- <TouchableOpacity
|
|
|
- style={{ flex: 1 }}
|
|
|
- onPress={() => this.presentFullscreenPlayer()}
|
|
|
+ <View
|
|
|
+ style={{
|
|
|
+ flex: 1,
|
|
|
+ alignItems: "center"
|
|
|
+ }}
|
|
|
>
|
|
|
- <View style={{ flex: 1 }}>
|
|
|
+ <TouchableOpacity
|
|
|
+ style={{
|
|
|
+ justifyContent: "center",
|
|
|
+ width: "100%",
|
|
|
+ height: "100%"
|
|
|
+ }}
|
|
|
+ onPress={() => this.presentFullscreenPlayer()}
|
|
|
+ >
|
|
|
{/* //放大按钮 */}
|
|
|
- <Image style={[styles.player_pause_icon]} />
|
|
|
- </View>
|
|
|
- </TouchableOpacity>
|
|
|
+ <Image
|
|
|
+ style={[styles.fullscreen_icon]}
|
|
|
+ source={require("../images/video/fullscreen.png")}
|
|
|
+ />
|
|
|
+ </TouchableOpacity>
|
|
|
+ </View>
|
|
|
</View>
|
|
|
</View>
|
|
|
);
|
|
@@ -131,14 +180,20 @@ export default class CusVideo extends React.Component {
|
|
|
loadStart() {
|
|
|
// alert("loadStart");
|
|
|
}
|
|
|
+ onBuffer({ isBuffering }: { isBuffering: boolean }) {
|
|
|
+ //true为正在加载,false为没有加载,此处给loading提示
|
|
|
+ console.log("isBuffering:" + isBuffering);
|
|
|
+ }
|
|
|
onLoad = data => {
|
|
|
//获取的是秒数
|
|
|
this.setState({ duration: data.duration });
|
|
|
+ this.seekbar.setMax(data.duration);
|
|
|
};
|
|
|
onProgress = data => {
|
|
|
this.setState({
|
|
|
currentTime: data.currentTime
|
|
|
});
|
|
|
+ this.seekbar.setProgress(this.state.currentTime);
|
|
|
};
|
|
|
|
|
|
onError() {
|
|
@@ -155,21 +210,48 @@ export default class CusVideo extends React.Component {
|
|
|
}
|
|
|
}
|
|
|
pause() {
|
|
|
- this.setState({ paused: true });
|
|
|
+ this.setState({
|
|
|
+ paused: true,
|
|
|
+ player_status_icon: require("../images/video/start.png")
|
|
|
+ });
|
|
|
this.player_icon_index = 1;
|
|
|
}
|
|
|
start() {
|
|
|
- this.setState({ paused: false });
|
|
|
+ this.setState({
|
|
|
+ paused: false,
|
|
|
+ player_status_icon: require("../images/video/pause.png")
|
|
|
+ });
|
|
|
this.player_icon_index = 0;
|
|
|
}
|
|
|
showToast(params) {
|
|
|
// ToastExample.message(params);
|
|
|
ToastExample.show(params, ToastExample.SHORT);
|
|
|
}
|
|
|
+ seekTo(progress) {
|
|
|
+ this.player.seek(progress);
|
|
|
+ }
|
|
|
presentFullscreenPlayer() {
|
|
|
- // alert("点击调用全屏");
|
|
|
+ if (this.state.isFull) {
|
|
|
+ this.setState({
|
|
|
+ isFull: false,
|
|
|
+ needback: this.props.needback
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.setState({
|
|
|
+ isFull: true,
|
|
|
+ needback: true
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
this.props.videofullScreenPlayer();
|
|
|
- // this.player.presentFullscreenPlayer();
|
|
|
+ this.seekbar.setProgress(this.state.currentTime);
|
|
|
+ }
|
|
|
+ touch_up_callback(progress) {
|
|
|
+ //抬起之后,获取算出来的progress
|
|
|
+ this.setState({
|
|
|
+ currentTime: progress
|
|
|
+ });
|
|
|
+ this.seekTo(progress);
|
|
|
}
|
|
|
|
|
|
refreshVideo() {
|
|
@@ -178,6 +260,17 @@ export default class CusVideo extends React.Component {
|
|
|
currentTime: 0
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ videoBackClick() {
|
|
|
+ // if (this.props.needback != undefined && this.props.needback) {
|
|
|
+ // }
|
|
|
+ if (this.state.isFull) {
|
|
|
+ //全屏状态下,变小屏
|
|
|
+ this.presentFullscreenPlayer();
|
|
|
+ } else {
|
|
|
+ this.props.videoback();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
@@ -187,15 +280,23 @@ const styles = StyleSheet.create({
|
|
|
width: "100%",
|
|
|
height: 50,
|
|
|
alignItems: "center",
|
|
|
+ justifyContent: "center",
|
|
|
bottom: 0
|
|
|
},
|
|
|
player_pause_icon: {
|
|
|
- width: "100%",
|
|
|
+ width: "80%",
|
|
|
resizeMode: "center",
|
|
|
- height: "80%",
|
|
|
+ height: "40%",
|
|
|
justifyContent: "center",
|
|
|
alignItems: "center",
|
|
|
- backgroundColor: "blue"
|
|
|
+ left: 5
|
|
|
+ },
|
|
|
+ fullscreen_icon: {
|
|
|
+ width: "80%",
|
|
|
+ resizeMode: "center",
|
|
|
+ height: "30%",
|
|
|
+ justifyContent: "center",
|
|
|
+ alignItems: "center"
|
|
|
},
|
|
|
player_time: {
|
|
|
fontSize: 18,
|
|
@@ -227,3 +328,45 @@ function formatTime(s) {
|
|
|
s = s.length == 1 ? "0" + s : s;
|
|
|
return h + ":" + s;
|
|
|
}
|
|
|
+class VideoBack extends Component {
|
|
|
+ render() {
|
|
|
+ if (this.props.needback) {
|
|
|
+ return (
|
|
|
+ <TouchableOpacity
|
|
|
+ //点击事件放在这个组件里才管用
|
|
|
+ style={{
|
|
|
+ justifyContent: "center",
|
|
|
+ width: "100%",
|
|
|
+ height: "100%"
|
|
|
+ }}
|
|
|
+ onPress={() => this.props.videoback()}
|
|
|
+ >
|
|
|
+ <Image
|
|
|
+ style={[styles.player_pause_icon]}
|
|
|
+ source={require("../images/video/back.png")}
|
|
|
+ />
|
|
|
+ </TouchableOpacity>
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ 使用方法
|
|
|
+ <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
|
|
|
+ }}
|
|
|
+ />
|
|
|
+
|
|
|
+
|
|
|
+ */
|