SchedulePage.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /**
  2. * Sample React Native App
  3. * https://github.com/facebook/react-native
  4. *
  5. * @format
  6. * @flow
  7. */
  8. import React, { Component } from "react";
  9. import {
  10. Platform,
  11. StyleSheet,
  12. Text,
  13. View,
  14. Image,
  15. TouchableOpacity,
  16. ImageBackground,
  17. FlatList,
  18. findNodeHandle,
  19. UIManager,
  20. StatusBar,
  21. BackHandler,
  22. Button,
  23. DeviceEventEmitter
  24. } from "react-native";
  25. import Orientation from "react-native-orientation";
  26. import AndroidUtil from "../../util/AndroidUtil";
  27. import BasePage from "../BasePage";
  28. import CourseTitle from "./CourseTitle";
  29. import ScheduleFlatItem from "./ScheduleFlatItem";
  30. import CusVideo from "./CusVideo";
  31. const instructions = Platform.select({
  32. ios: "Press Cmd+R to reload,\n" + "Cmd+D or shake for dev menu",
  33. android:
  34. "Double tap R on your keyboard to reload,\n" +
  35. "Shake or press menu button for dev menu"
  36. });
  37. type Props = {};
  38. export default class SchedulePage extends BasePage {
  39. constructor(props) {
  40. super(props);
  41. this.state = {
  42. statusbar_hidden: false,
  43. video_show: false,
  44. x: 0.0,
  45. y: 0.0,
  46. videoImg_flex: 1,
  47. videoImage_width: 0,
  48. videoImage_height: 0,
  49. videoImage_x: 0.0,
  50. videoImage_y: 0.0,
  51. video_uri:
  52. "https://www.apple.com/105/media/cn/iphone-x/2017/01df5b43-28e4-4848-bf20-490c34a926a7/films/feature/iphone-x-feature-cn-20170912_1280x720h.mp4",
  53. title_height: "6%",
  54. video_frame_height: "32%",
  55. seat_height: "2%",
  56. flatlist_height: "60%",
  57. isFull: false,
  58. playing_key: 0
  59. };
  60. }
  61. render() {
  62. return (
  63. <View
  64. style={{
  65. flex: 1
  66. }}
  67. >
  68. <StatusBar
  69. // backgroundColor={"transparent"}
  70. barStyle={"dark-content"}
  71. backgroundColor={"white"}
  72. translucent={false}
  73. hidden={this.state.statusbar_hidden}
  74. />
  75. <View
  76. style={{
  77. flex: 1,
  78. backgroundColor: "#F3F3F3",
  79. justifyContent: "center",
  80. alignItems: "center"
  81. }}
  82. >
  83. <View
  84. style={{
  85. height: this.state.title_height,
  86. backgroundColor: "white"
  87. }}
  88. >
  89. <CourseTitle
  90. width={this.getWindowWidth()}
  91. title="第12周 爱上幼儿园"
  92. lefttype={1}
  93. righttype={1}
  94. textcolor={"#231F20"}
  95. backPress={() => this.goBack()}
  96. // backPress={() => alert("左侧按钮")}
  97. rightPress={() => alert("右侧按钮")}
  98. />
  99. </View>
  100. <View
  101. style={{
  102. height: this.state.video_frame_height,
  103. width: "100%"
  104. }}
  105. >
  106. <Image
  107. source={{
  108. uri:
  109. "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556277324856&di=dc1548a0c5ba10481af922e174912937&imgtype=0&src=http%3A%2F%2Fwww.51pptmoban.com%2Fd%2Ffile%2F2012%2F05%2F12%2F82c4568a90055adcf8fbb896f0841c69.jpg"
  110. }}
  111. style={{
  112. width: "100%",
  113. height: "100%"
  114. }}
  115. ref={c => {
  116. this.video_image = c;
  117. }}
  118. />
  119. </View>
  120. <View
  121. style={{
  122. height: this.state.seat_height
  123. }}
  124. />
  125. <View
  126. style={{
  127. height: this.state.flatlist_height,
  128. justifyContent: "center",
  129. alignItems: "center",
  130. width: "100%"
  131. }}
  132. >
  133. <FlatList
  134. ItemSeparatorComponent={() => (
  135. <View
  136. style={{
  137. height: 10
  138. }}
  139. />
  140. )}
  141. ListFooterComponent={() => (
  142. <View
  143. style={{
  144. height: 30
  145. }}
  146. />
  147. )}
  148. renderItem={({ item }) => {
  149. return this.loadFlatItem(item);
  150. }}
  151. keyExtractor={(item, index) => item.key.toString()}
  152. horizontal={false}
  153. data={[
  154. {
  155. key: 1,
  156. typecolor: "#74E0FF",
  157. typename: "习惯养成",
  158. videoname: "碗里不剩一粒米",
  159. videourl: "碗里不剩一粒米xxxx"
  160. },
  161. {
  162. key: 2,
  163. typecolor: "#FB5B76",
  164. typename: "品格礼仪",
  165. videoname: "我有很多朋友",
  166. videourl: "我有很多朋友xxxx"
  167. },
  168. {
  169. key: 3,
  170. typecolor: "#EC48E1",
  171. typename: "自我保护",
  172. videoname: "小猫喵喵叫",
  173. videourl: "小猫喵喵叫xxxx"
  174. },
  175. {
  176. key: 4,
  177. typecolor: "#39D6B9",
  178. typename: "亲子游戏",
  179. videoname: "安静的睡前游戏-全家人都睡了",
  180. videourl: "安静的睡前游戏xxxx"
  181. },
  182. {
  183. key: 5,
  184. typecolor: "#3397F0",
  185. typename: "欢乐音乐",
  186. videoname: "小鸡捉虫子",
  187. videourl: "小鸡捉虫子xxxx"
  188. },
  189. {
  190. key: 11,
  191. typecolor: "#74E0FF",
  192. typename: "习惯养成",
  193. videoname: "碗里不剩一粒米",
  194. videourl: "碗里不剩一粒米xxxx"
  195. },
  196. {
  197. key: 12,
  198. typecolor: "#FB5B76",
  199. typename: "品格礼仪",
  200. videoname: "我有很多朋友",
  201. videourl: "我有很多朋友xxxx"
  202. },
  203. {
  204. key: 13,
  205. typecolor: "#EC48E1",
  206. typename: "自我保护",
  207. videoname: "小猫喵喵叫",
  208. videourl: "小猫喵喵叫xxxx"
  209. },
  210. {
  211. key: 14,
  212. typecolor: "#39D6B9",
  213. typename: "亲子游戏",
  214. videoname: "安静的睡前游戏-全家人都睡了",
  215. videourl:
  216. "https://www.apple.com/105/media/cn/iphone-x/2017/01df5b43-28e4-4848-bf20-490c34a926a7/films/feature/iphone-x-feature-cn-20170912_1280x720h.mp4"
  217. },
  218. {
  219. key: 15,
  220. typecolor: "#3397F0",
  221. typename: "欢乐音乐",
  222. videoname: "小鸡捉虫子",
  223. videourl: "http://chimee.org/vod/1.mp4"
  224. }
  225. ]}
  226. />
  227. </View>
  228. </View>
  229. <CusVideo
  230. show={this.state.video_show}
  231. uri={this.state.video_uri}
  232. ref={view => (this.video = view)}
  233. videofullScreenPlayer={this.fullScreenPlayer.bind(this)}
  234. onError={this.onError.bind(this)}
  235. onEnd={this.onEnd.bind(this)}
  236. style={{
  237. left: this.state.x,
  238. top: this.state.y,
  239. width: this.state.video_width,
  240. height: this.state.video_height,
  241. overflow: "hidden",
  242. position: "absolute"
  243. }}
  244. />
  245. </View>
  246. );
  247. }
  248. loadFlatItem(data) {
  249. return (
  250. <ScheduleFlatItem
  251. width={this.getWindowWidth() * 0.9}
  252. height={50}
  253. data={data}
  254. onPress={() => this.changeUrl(data)}
  255. />
  256. );
  257. }
  258. componentWillMount() {
  259. BackHandler.addEventListener(
  260. "hardwareBackPress",
  261. this.onBackAndroid.bind(this)
  262. );
  263. }
  264. componentWillUnmount() {
  265. BackHandler.removeEventListener(
  266. "hardwareBackPress",
  267. this.onBackAndroid.bind(this)
  268. );
  269. }
  270. onBackAndroid() {
  271. if (this.state.isFull) {
  272. return true;
  273. } else {
  274. }
  275. }
  276. onError() {
  277. alert("播放器异常");
  278. this.setState({
  279. video_show: false
  280. });
  281. }
  282. onEnd() {
  283. alert("播放结束");
  284. this.video.refreshVideo();
  285. }
  286. fullScreenPlayer() {
  287. if (!this.state.isFull) {
  288. Orientation.lockToLandscape();
  289. this.setState({
  290. video_frame_height: "100%",
  291. statusbar_hidden: true,
  292. isFull: true,
  293. x: 0,
  294. y: 0,
  295. video_width: "100%",
  296. video_height: "100%"
  297. });
  298. } else {
  299. Orientation.lockToPortrait();
  300. this.setState({
  301. video_frame_height: "32%",
  302. x: this.state.videoImage_x,
  303. y: this.state.videoImage_y,
  304. video_width: this.state.videoImage_width,
  305. video_height: this.state.videoImage_height,
  306. statusbar_hidden: false,
  307. isFull: false
  308. });
  309. }
  310. }
  311. changeUrl(data) {
  312. //切换视频并且播放
  313. // alert(url);
  314. if (this.state.playing_key == data.key) {
  315. return;
  316. }
  317. const handle = findNodeHandle(this.video_image);
  318. setTimeout(() => {
  319. UIManager.measure(handle, (x, y, width, height, pageX, pageY) => {
  320. this.setState({
  321. x: pageX,
  322. y: pageY,
  323. video_width: width,
  324. video_height: height,
  325. videoImage_width: width,
  326. videoImage_height: height,
  327. videoImage_x: pageX,
  328. videoImage_y: pageY,
  329. video_show: true,
  330. video_uri: data.videourl,
  331. playing_key: data.key
  332. });
  333. });
  334. }, 0);
  335. this.video.start();
  336. }
  337. }