/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/
import React, { Component } from "react";
import {
Platform,
StyleSheet,
Text,
View,
Image,
TouchableOpacity,
ImageBackground,
FlatList,
findNodeHandle,
UIManager,
StatusBar,
BackHandler,
Button,
DeviceEventEmitter
} from "react-native";
import Orientation from "react-native-orientation";
import AndroidUtil from "../../util/AndroidUtil";
import BasePage from "../BasePage";
import CourseTitle from "./CourseTitle";
import ScheduleFlatItem from "./ScheduleFlatItem";
import CusVideo from "./CusVideo";
const instructions = Platform.select({
ios: "Press Cmd+R to reload,\n" + "Cmd+D or shake for dev menu",
android:
"Double tap R on your keyboard to reload,\n" +
"Shake or press menu button for dev menu"
});
type Props = {};
export default class SchedulePage extends BasePage {
constructor(props) {
super(props);
this.state = {
statusbar_hidden: false,
video_show: false,
x: 0.0,
y: 0.0,
videoImg_flex: 1,
videoImage_width: 0,
videoImage_height: 0,
videoImage_x: 0.0,
videoImage_y: 0.0,
video_uri:
"https://www.apple.com/105/media/cn/iphone-x/2017/01df5b43-28e4-4848-bf20-490c34a926a7/films/feature/iphone-x-feature-cn-20170912_1280x720h.mp4",
title_height: "6%",
video_frame_height: "32%",
seat_height: "2%",
flatlist_height: "60%",
isFull: false,
playing_key: 0
};
}
render() {
return (
this.goBack()}
// backPress={() => alert("左侧按钮")}
rightPress={() => alert("右侧按钮")}
/>
{
this.video_image = c;
}}
/>
(
)}
ListFooterComponent={() => (
)}
renderItem={({ item }) => {
return this.loadFlatItem(item);
}}
keyExtractor={(item, index) => item.key.toString()}
horizontal={false}
data={[
{
key: 1,
typecolor: "#74E0FF",
typename: "习惯养成",
videoname: "碗里不剩一粒米",
videourl: "碗里不剩一粒米xxxx"
},
{
key: 2,
typecolor: "#FB5B76",
typename: "品格礼仪",
videoname: "我有很多朋友",
videourl: "我有很多朋友xxxx"
},
{
key: 3,
typecolor: "#EC48E1",
typename: "自我保护",
videoname: "小猫喵喵叫",
videourl: "小猫喵喵叫xxxx"
},
{
key: 4,
typecolor: "#39D6B9",
typename: "亲子游戏",
videoname: "安静的睡前游戏-全家人都睡了",
videourl: "安静的睡前游戏xxxx"
},
{
key: 5,
typecolor: "#3397F0",
typename: "欢乐音乐",
videoname: "小鸡捉虫子",
videourl: "小鸡捉虫子xxxx"
},
{
key: 11,
typecolor: "#74E0FF",
typename: "习惯养成",
videoname: "碗里不剩一粒米",
videourl: "碗里不剩一粒米xxxx"
},
{
key: 12,
typecolor: "#FB5B76",
typename: "品格礼仪",
videoname: "我有很多朋友",
videourl: "我有很多朋友xxxx"
},
{
key: 13,
typecolor: "#EC48E1",
typename: "自我保护",
videoname: "小猫喵喵叫",
videourl: "小猫喵喵叫xxxx"
},
{
key: 14,
typecolor: "#39D6B9",
typename: "亲子游戏",
videoname: "安静的睡前游戏-全家人都睡了",
videourl:
"https://www.apple.com/105/media/cn/iphone-x/2017/01df5b43-28e4-4848-bf20-490c34a926a7/films/feature/iphone-x-feature-cn-20170912_1280x720h.mp4"
},
{
key: 15,
typecolor: "#3397F0",
typename: "欢乐音乐",
videoname: "小鸡捉虫子",
videourl: "http://chimee.org/vod/1.mp4"
}
]}
/>
(this.video = view)}
videofullScreenPlayer={this.fullScreenPlayer.bind(this)}
onError={this.onError.bind(this)}
onEnd={this.onEnd.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"
}}
/>
);
}
loadFlatItem(data) {
return (
this.changeUrl(data)}
/>
);
}
componentWillMount() {
BackHandler.addEventListener(
"hardwareBackPress",
this.onBackAndroid.bind(this)
);
}
componentWillUnmount() {
BackHandler.removeEventListener(
"hardwareBackPress",
this.onBackAndroid.bind(this)
);
}
onBackAndroid() {
if (this.state.isFull) {
return true;
} else {
}
}
onError() {
alert("播放器异常");
this.setState({
video_show: false
});
}
onEnd() {
alert("播放结束");
this.video.refreshVideo();
}
fullScreenPlayer() {
if (!this.state.isFull) {
Orientation.lockToLandscape();
this.setState({
video_frame_height: "100%",
statusbar_hidden: true,
isFull: true,
x: 0,
y: 0,
video_width: "100%",
video_height: "100%"
});
} else {
Orientation.lockToPortrait();
this.setState({
video_frame_height: "32%",
x: this.state.videoImage_x,
y: this.state.videoImage_y,
video_width: this.state.videoImage_width,
video_height: this.state.videoImage_height,
statusbar_hidden: false,
isFull: false
});
}
}
changeUrl(data) {
//切换视频并且播放
// alert(url);
if (this.state.playing_key == data.key) {
return;
}
const handle = findNodeHandle(this.video_image);
setTimeout(() => {
UIManager.measure(handle, (x, y, width, height, pageX, pageY) => {
this.setState({
x: pageX,
y: pageY,
video_width: width,
video_height: height,
videoImage_width: width,
videoImage_height: height,
videoImage_x: pageX,
videoImage_y: pageY,
video_show: true,
video_uri: data.videourl,
playing_key: data.key
});
});
}, 0);
this.video.start();
}
}