SchedulePage.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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. needback={false}
  234. videoback={() => alert("videoback")}
  235. videofullScreenPlayer={this.fullScreenPlayer.bind(this)}
  236. onError={this.onError.bind(this)}
  237. onEnd={this.onEnd.bind(this)}
  238. style={{
  239. left: this.state.x,
  240. top: this.state.y,
  241. width: this.state.video_width,
  242. height: this.state.video_height,
  243. overflow: "hidden",
  244. position: "absolute"
  245. }}
  246. />
  247. </View>
  248. );
  249. }
  250. loadFlatItem(data) {
  251. return (
  252. <ScheduleFlatItem
  253. width={this.getWindowWidth() * 0.9}
  254. height={50}
  255. data={data}
  256. onPress={() => this.changeUrl(data)}
  257. />
  258. );
  259. }
  260. componentWillMount() {
  261. BackHandler.addEventListener(
  262. "hardwareBackPress",
  263. this.onBackAndroid.bind(this)
  264. );
  265. }
  266. componentWillUnmount() {
  267. BackHandler.removeEventListener(
  268. "hardwareBackPress",
  269. this.onBackAndroid.bind(this)
  270. );
  271. }
  272. onBackAndroid() {
  273. if (this.state.isFull) {
  274. Orientation.lockToPortrait();
  275. this.setState({
  276. // title_height: "6%",
  277. video_frame_height: "32%",
  278. // seat_height: "2%",
  279. // flatlist_height: "60%",
  280. x: this.state.videoImage_x,
  281. y: this.state.videoImage_y,
  282. video_width: this.state.videoImage_width,
  283. video_height: this.state.videoImage_height,
  284. statusbar_hidden: false,
  285. isFull: false
  286. });
  287. return true;
  288. } else {
  289. }
  290. }
  291. onError() {
  292. alert("播放器异常");
  293. this.setState({
  294. video_show: false
  295. });
  296. }
  297. onEnd() {
  298. alert("播放结束");
  299. this.video.refreshVideo();
  300. }
  301. fullScreenPlayer() {
  302. if (!this.state.isFull) {
  303. Orientation.lockToLandscape();
  304. this.setState({
  305. video_frame_height: "100%",
  306. statusbar_hidden: true,
  307. isFull: true,
  308. x: 0,
  309. y: 0,
  310. video_width: "100%",
  311. video_height: "100%"
  312. });
  313. } else {
  314. Orientation.lockToPortrait();
  315. this.setState({
  316. video_frame_height: "32%",
  317. x: this.state.videoImage_x,
  318. y: this.state.videoImage_y,
  319. video_width: this.state.videoImage_width,
  320. video_height: this.state.videoImage_height,
  321. statusbar_hidden: false,
  322. isFull: false
  323. });
  324. }
  325. }
  326. changeUrl(data) {
  327. //切换视频并且播放
  328. // alert(url);
  329. if (this.state.playing_key == data.key) {
  330. return;
  331. }
  332. const handle = findNodeHandle(this.video_image);
  333. setTimeout(() => {
  334. UIManager.measure(handle, (x, y, width, height, pageX, pageY) => {
  335. this.setState({
  336. x: pageX,
  337. y: pageY,
  338. video_width: width,
  339. video_height: height,
  340. videoImage_width: width,
  341. videoImage_height: height,
  342. videoImage_x: pageX,
  343. videoImage_y: pageY,
  344. video_show: true,
  345. video_uri: data.videourl,
  346. playing_key: data.key
  347. });
  348. });
  349. }, 0);
  350. this.video.start();
  351. }
  352. }