VideoExplain.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. StyleSheet,
  11. Text,
  12. View,
  13. Image,
  14. ScrollView,
  15. StatusBar,
  16. BackHandler,
  17. FlatList,
  18. TouchableOpacity
  19. } from "react-native";
  20. import Orientation from "react-native-orientation";
  21. import CusVideo from "./CusVideo";
  22. // 获取屏幕宽高
  23. import { Dimensions } from 'react-native'
  24. const { height, width } = Dimensions.get('window');
  25. export default class VideoExplain extends Component {
  26. static propTypes = {
  27. // uri: PropTypes.string,
  28. // title: PropTypes.string,
  29. // details: PropTypes.string,
  30. };
  31. state = {
  32. isFull: false,
  33. video_height: 210,
  34. statusbar_hidden: false,
  35. videoStyle: {
  36. width: "100%"
  37. },
  38. collectImage: require('../images/courseDetails/collect.png'),
  39. isCollect: true
  40. };
  41. render() {
  42. return (
  43. <View style={this.state.videoStyle}>
  44. <StatusBar
  45. // backgroundColor={"transparent"}
  46. barStyle={"dark-content"}
  47. backgroundColor={"white"}
  48. translucent={false}
  49. hidden={this.state.statusbar_hidden}
  50. />
  51. {/* <View style={{ width: "100%", height: 210 }} /> */}
  52. <CusVideo
  53. show={true} //是否显示
  54. uri={this.props.uri} //播放路径
  55. ref={view => (this.video = view)} //设置ID
  56. needback={true}
  57. videoback={this.back.bind(this)}
  58. videofullScreenPlayer={this.fullScreenPlayer.bind(this)}
  59. onError={this.onError.bind(this)}
  60. onEnd={this.onEnd.bind(this)}
  61. style={{
  62. width: "100%",
  63. height: this.state.video_height
  64. }}
  65. />
  66. <View style={styles.videoExplain}>
  67. <View style={styles.title}>
  68. <Text style={styles.font}>{this.props.dataList}</Text>
  69. <View style={styles.icon}>
  70. <TouchableOpacity onPress={this.collection.bind(this)}>
  71. <Image source={this.state.collectImage} style={styles.iconSize} />
  72. </TouchableOpacity>
  73. <TouchableOpacity onPress={this.share}>
  74. <Image source={require('../images/courseDetails/share.png')} style={styles.iconSize} />
  75. </TouchableOpacity>
  76. </View>
  77. </View>
  78. <View style={[styles.title, styles.tops]}>
  79. <Text style={styles.font}>课程介绍:</Text>
  80. <Text style={styles.clor}>更多 ></Text>
  81. </View>
  82. <Text style={styles.clor}>{this.props.details}</Text>
  83. </View>
  84. </View>
  85. );
  86. }
  87. // 全屏播放
  88. fullScreenPlayer() {
  89. if (!this.state.isFull) {
  90. Orientation.lockToLandscape();
  91. this.setState({
  92. statusbar_hidden: true,
  93. isFull: true,
  94. video_height: "100%",
  95. videoStyle: {
  96. width: "100%",
  97. height: width
  98. }
  99. });
  100. } else {
  101. Orientation.lockToPortrait();
  102. this.setState({
  103. statusbar_hidden: false,
  104. isFull: false,
  105. video_height: 210,
  106. videoStyle: {
  107. width: "100%"
  108. }
  109. });
  110. }
  111. this.props.full(this.state.isFull);
  112. }
  113. // 播放器异常
  114. onError() {
  115. alert("播放器异常");
  116. }
  117. // 播放结束
  118. onEnd() {
  119. alert("播放结束");
  120. this.video.refreshVideo();
  121. }
  122. back(){
  123. this.props.videoback();
  124. }
  125. componentWillMount() {
  126. this.backlistener=BackHandler.addEventListener(
  127. "hardwareBackPress",
  128. this.onBackAndroid
  129. );
  130. }
  131. componentWillUnmount() {
  132. console.log("componentWillUnmount")
  133. if( this.backlistener){
  134. BackHandler.removeEventListener(
  135. "hardwareBackPress",
  136. this.onBackAndroid
  137. );
  138. }
  139. }
  140. // 播放器返回
  141. onBackAndroid=() => {
  142. if (this.state.isFull) {
  143. return true;
  144. } else {
  145. alert("返回。。。");
  146. }
  147. }
  148. // 收藏
  149. collection() {
  150. if (this.state.isCollect) {
  151. this.setState({
  152. collectImage: require('../images/courseDetails/have_collect.png'),
  153. isCollect: false
  154. })
  155. }else {
  156. this.setState({
  157. collectImage: require('../images/courseDetails/collect.png'),
  158. isCollect: true
  159. })
  160. }
  161. }
  162. // 分享
  163. share() {
  164. alert('点击分享')
  165. }
  166. }
  167. const styles = StyleSheet.create({
  168. videoExplain: {
  169. width: "100%",
  170. backgroundColor: "white",
  171. paddingLeft: 20,
  172. paddingRight: 20,
  173. paddingTop: 13,
  174. paddingBottom: 13
  175. },
  176. title: {
  177. width: "100%",
  178. display: "flex",
  179. flexDirection: "row",
  180. justifyContent: "space-between",
  181. alignItems: "center"
  182. },
  183. font: {
  184. fontSize: 18,
  185. color: "black",
  186. fontWeight: "bold"
  187. },
  188. clor: {
  189. fontSize: 14,
  190. color: "black"
  191. },
  192. icon: {
  193. display: "flex",
  194. flexDirection: "row"
  195. },
  196. iconSize: {
  197. width: 20,
  198. height: 20,
  199. marginLeft: 10
  200. },
  201. tops: {
  202. marginTop: 18
  203. }
  204. });