SchedulePage.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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 style={{ height: this.state.seat_height }} />
  120. <View
  121. style={{
  122. height: this.state.flatlist_height,
  123. justifyContent: "center",
  124. alignItems: "center",
  125. width: "100%"
  126. }}
  127. >
  128. <FlatList
  129. ItemSeparatorComponent={() => (
  130. <View
  131. style={{
  132. height: 10
  133. }}
  134. />
  135. )}
  136. ListFooterComponent={() => (
  137. <View
  138. style={{
  139. height: 30
  140. }}
  141. />
  142. )}
  143. renderItem={({ item }) => {
  144. return this.loadFlatItem(item);
  145. }}
  146. keyExtractor={(item, index) => item.key.toString()}
  147. horizontal={false}
  148. data={[
  149. {
  150. key: 1,
  151. typecolor: "#74E0FF",
  152. typename: "习惯养成",
  153. videoname: "碗里不剩一粒米",
  154. videourl: "碗里不剩一粒米xxxx"
  155. },
  156. {
  157. key: 2,
  158. typecolor: "#FB5B76",
  159. typename: "品格礼仪",
  160. videoname: "我有很多朋友",
  161. videourl: "我有很多朋友xxxx"
  162. },
  163. {
  164. key: 3,
  165. typecolor: "#EC48E1",
  166. typename: "自我保护",
  167. videoname: "小猫喵喵叫",
  168. videourl: "小猫喵喵叫xxxx"
  169. },
  170. {
  171. key: 4,
  172. typecolor: "#39D6B9",
  173. typename: "亲子游戏",
  174. videoname: "安静的睡前游戏-全家人都睡了",
  175. videourl: "安静的睡前游戏xxxx"
  176. },
  177. {
  178. key: 5,
  179. typecolor: "#3397F0",
  180. typename: "欢乐音乐",
  181. videoname: "小鸡捉虫子",
  182. videourl: "小鸡捉虫子xxxx"
  183. },
  184. {
  185. key: 11,
  186. typecolor: "#74E0FF",
  187. typename: "习惯养成",
  188. videoname: "碗里不剩一粒米",
  189. videourl: "碗里不剩一粒米xxxx"
  190. },
  191. {
  192. key: 12,
  193. typecolor: "#FB5B76",
  194. typename: "品格礼仪",
  195. videoname: "我有很多朋友",
  196. videourl: "我有很多朋友xxxx"
  197. },
  198. {
  199. key: 13,
  200. typecolor: "#EC48E1",
  201. typename: "自我保护",
  202. videoname: "小猫喵喵叫",
  203. videourl: "小猫喵喵叫xxxx"
  204. },
  205. {
  206. key: 14,
  207. typecolor: "#39D6B9",
  208. typename: "亲子游戏",
  209. videoname: "安静的睡前游戏-全家人都睡了",
  210. videourl:
  211. "https://www.apple.com/105/media/cn/iphone-x/2017/01df5b43-28e4-4848-bf20-490c34a926a7/films/feature/iphone-x-feature-cn-20170912_1280x720h.mp4"
  212. },
  213. {
  214. key: 15,
  215. typecolor: "#3397F0",
  216. typename: "欢乐音乐",
  217. videoname: "小鸡捉虫子",
  218. videourl: "http://chimee.org/vod/1.mp4"
  219. }
  220. ]}
  221. />
  222. </View>
  223. </View>
  224. <CusVideo
  225. show={this.state.video_show}
  226. uri={this.state.video_uri}
  227. ref={view => (this.video = view)}
  228. needback={false}
  229. videoback={() => alert("videoback")}
  230. videofullScreenPlayer={this.fullScreenPlayer.bind(this)}
  231. onError={this.onError.bind(this)}
  232. onEnd={this.onEnd.bind(this)}
  233. style={{
  234. left: this.state.x,
  235. top: this.state.y,
  236. width: this.state.video_width,
  237. height: this.state.video_height,
  238. overflow: "hidden",
  239. position: "absolute"
  240. }}
  241. />
  242. </View>
  243. );
  244. }
  245. loadFlatItem(data) {
  246. return (
  247. <ScheduleFlatItem
  248. width={this.getWindowWidth() * 0.9}
  249. height={50}
  250. data={data}
  251. onPress={() => this.changeUrl(data)}
  252. />
  253. );
  254. }
  255. onError() {
  256. alert("播放器异常");
  257. }
  258. onEnd() {
  259. alert("播放结束");
  260. this.video.refreshVideo();
  261. }
  262. fullScreenPlayer() {
  263. if (!this.state.isFull) {
  264. Orientation.lockToLandscape();
  265. this.setState({
  266. // title_height: "0%",
  267. video_frame_height: "100%",
  268. // seat_height: "0%",
  269. // flatlist_height: "0%",
  270. statusbar_hidden: true,
  271. isFull: true,
  272. x: 0,
  273. y: 0,
  274. video_width: "100%",
  275. video_height: "100%"
  276. });
  277. } else {
  278. Orientation.lockToPortrait();
  279. this.setState({
  280. // title_height: "6%",
  281. video_frame_height: "32%",
  282. // seat_height: "2%",
  283. // flatlist_height: "60%",
  284. x: this.state.videoImage_x,
  285. y: this.state.videoImage_y,
  286. video_width: this.state.videoImage_width,
  287. video_height: this.state.videoImage_height,
  288. statusbar_hidden: false,
  289. isFull: false
  290. });
  291. }
  292. }
  293. changeUrl(data) {
  294. //切换视频并且播放
  295. // alert(url);
  296. if (this.state.playing_key == data.key) {
  297. return;
  298. }
  299. const handle = findNodeHandle(this.video_image);
  300. setTimeout(() => {
  301. UIManager.measure(handle, (x, y, width, height, pageX, pageY) => {
  302. this.setState({
  303. x: pageX,
  304. y: pageY,
  305. video_width: width,
  306. video_height: height,
  307. videoImage_width: width,
  308. videoImage_height: height,
  309. videoImage_x: pageX,
  310. videoImage_y: pageY,
  311. video_show: true,
  312. video_uri: data.videourl,
  313. playing_key: data.key
  314. });
  315. });
  316. }, 0);
  317. this.video.start();
  318. }
  319. }