SchedulePage.js 9.5 KB

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