No Description

CAVideoDetailView.js 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /**
  2. * Created by Sean on 2018/5/9.
  3. */
  4. import {
  5. View,
  6. Text,
  7. StyleSheet,
  8. TouchableOpacity,
  9. ScrollView,
  10. SectionList,
  11. FlatList
  12. } from 'react-native'
  13. import React, {Component} from 'react'
  14. import {NavigationBarHeight, TabBarHeight, ScreenDimensions} from '../../../utils/DimensionsTools'
  15. import Video from 'react-native-video'
  16. import CAVideoRecommend from './CAVideoRecommend';
  17. import CAVideoAnswerPage from './CAVideoAnswerPage';
  18. import CAVideoDiscussPage from './CAVideoDiscussPage';
  19. import CAVideoTranslationPage from './CAVideoTranslationPage';
  20. export default class CAVideoDetailView extends React.Component {
  21. constructor(props) {
  22. super(props)
  23. this.state = {
  24. currentPage: 0,
  25. showMp: true,
  26. rate: true,//播放数据
  27. showBtn: true,//进入 显示播放 按钮
  28. endBoolPlay: true,
  29. paused:false,//是否重新播放
  30. }
  31. }
  32. clickTagButtonActon(index) {
  33. let x = index * ScreenDimensions.width
  34. this.setState({currentPage: index})
  35. this._scrollView.scrollTo({x: x, y: 0, animated: true})
  36. }
  37. render() {
  38. return(
  39. <View style={styles.View}>
  40. <CAVideoContainer style={styles.videoContainer} />
  41. <Text style={styles.videoTitle}>How (and why) Russia hacker the US election</Text>
  42. <View style={styles.TagButtonBgView}>
  43. <TouchableOpacity onPress={() => {
  44. this.clickTagButtonActon(0)
  45. }}
  46. activeOpacity={1}
  47. style={[styles.TagButtonView, {
  48. borderBottomColor: this.state.currentPage === 0 ? '#fc2f1f' : '#efeff4',
  49. borderBottomWidth: this.state.currentPage === 0 ? 3 : 1,
  50. }]}>
  51. <Text style={[styles.TagButtonTitle, {marginLeft: 23}]}>{'推荐'}</Text>
  52. </TouchableOpacity>
  53. <TouchableOpacity onPress={() => {
  54. this.clickTagButtonActon(1)
  55. }}
  56. activeOpacity={1}
  57. style={[styles.TagButtonView, {
  58. borderBottomColor: this.state.currentPage === 1 ? '#fc2f1f' : '#efeff4',
  59. borderBottomWidth: this.state.currentPage === 1 ? 3 : 1,
  60. }]}>
  61. <Text style={[styles.TagButtonTitle, {marginLeft: 23}]}>{'答题'}</Text>
  62. </TouchableOpacity>
  63. <TouchableOpacity onPress={() => {
  64. this.clickTagButtonActon(2)
  65. }}
  66. activeOpacity={1}
  67. style={[styles.TagButtonView, {
  68. borderBottomColor: this.state.currentPage === 2 ? '#fc2f1f' : '#efeff4',
  69. borderBottomWidth: this.state.currentPage === 2 ? 3 : 1,
  70. }]}>
  71. <Text style={[styles.TagButtonTitle, {marginLeft: 23}]}>{'讨论'}</Text>
  72. </TouchableOpacity>
  73. <TouchableOpacity onPress={() => {
  74. this.clickTagButtonActon(3)
  75. }}
  76. activeOpacity={1}
  77. style={[styles.TagButtonView, {
  78. borderBottomColor: this.state.currentPage === 3 ? '#fc2f1f' : '#efeff4',
  79. borderBottomWidth: this.state.currentPage === 3 ? 3 : 1,
  80. }]}>
  81. <Text style={[styles.TagButtonTitle, {marginLeft: 23}]}>{'译文'}</Text>
  82. </TouchableOpacity>
  83. </View>
  84. <ScrollView ref = {(o) => {
  85. this._scrollView = o
  86. }} onMomentumScrollEnd={(e) => {
  87. this.onAnimationEnd(e)
  88. }} horizontal={true} pagingEnabled={true} style={styles.ScrollView}>
  89. <CAVideoRecommend />
  90. <CAVideoAnswerPage />
  91. <CAVideoDiscussPage />
  92. <CAVideoTranslationPage />
  93. </ScrollView>
  94. </View>
  95. );
  96. }
  97. onAnimationEnd(e){
  98. const offSetX = e.nativeEvent.contentOffset.x
  99. const currentPage = offSetX / (ScreenDimensions.width)
  100. this.setState({currentPage: currentPage})
  101. }
  102. }
  103. class CAVideoContainer extends Component {
  104. constructor(props) {
  105. super(props);
  106. this.state = {
  107. currentPage: 0,
  108. showMp: true,
  109. rate: false,//播放数据
  110. showBtn: true,//进入 显示播放 按钮
  111. endBoolPlay: true,
  112. paused:false,//是否重新播放
  113. }
  114. }
  115. componentWillReceiveProps(nextProps) {
  116. this.setState({
  117. rate: 1
  118. })
  119. }
  120. render() {
  121. return(
  122. <View style={[this.props.style, {backgroundColor: 'blue'}]}>
  123. <Video
  124. ref={(ref) => {
  125. this.video = ref
  126. }}
  127. source={require('../../../resources/MP4/2.mp4')}
  128. style={styles.videoContainer}
  129. rate={this.state.rate ? 1 : 0} // 控制暂停/播放,0 代表暂停paused, 1代表播放normal.
  130. paused={this.state.paused}
  131. volume={1} // 声音的放大倍数,0 代表没有声音,就是静音muted, 1 代表正常音量 normal,更大的数字表示放大的倍数
  132. muted={true} // true代表静音,默认为false.
  133. resizeMode='cover' // 视频的自适应伸缩铺放行为,
  134. onLoad={this.onLoad.bind(this)} // 当视频加载完毕时的回调函数
  135. onLoadStart={this.loadStart.bind(this)} // 当视频开始加载时的回调函数
  136. onProgress={this.onProgress.bind(this)} // 进度控制,每250ms调用一次,以获取视频播放的进度
  137. onEnd={this.onEnd.bind(this)} // 当视频播放完毕后的回调函数
  138. onError={this.videoError.bind(this)} // 当视频不能加载,或出错后的回调函数
  139. onAudioBecomingNoisy={this.onAudioBecomingNoisy.bind(this)}
  140. onAudioFocusChanged={this.onAudioFocusChanged.bind(this)}
  141. repeat={true} // 是否重复播放
  142. onBuffer={this.onBuffer} // 是否重复播放
  143. />
  144. </View>
  145. );
  146. }
  147. loadStart() {
  148. //需要 添加背景图片
  149. console.log("loadStart=======")
  150. }
  151. onProgress(time) {
  152. }
  153. onEnd() {
  154. this.setState({
  155. endBoolPlay: false,
  156. paused:true
  157. })
  158. }
  159. onError() {
  160. console.log("onError=======")
  161. }
  162. onAudioBecomingNoisy() {
  163. }
  164. onAudioFocusChanged() {
  165. }
  166. onLoad() {
  167. console.log("当视频加载完毕时的回调函数")
  168. this.setState({
  169. showMp: false
  170. })
  171. }
  172. videoError() {
  173. }
  174. onPressInput() {
  175. this.refs.chatInputBar.openInputBar();
  176. }
  177. _onSendMsg(text) {
  178. }
  179. onBuffer() {
  180. }
  181. onPressPlay() {
  182. //暂停 播放
  183. let rate = this.state.rate;
  184. let showBtn = this.state.showBtn;
  185. this.setState({
  186. rate: !rate,
  187. showBtn: false
  188. })
  189. }
  190. }
  191. const styles = StyleSheet.create({
  192. View: {
  193. flex: 1,
  194. backgroundColor: 'white'
  195. },
  196. videoContainer: {
  197. width: ScreenDimensions.width,
  198. height: ScreenDimensions.width * (203 / 360),
  199. },
  200. videoTitle: {
  201. fontSize: 18,
  202. fontWeight: 'bold',
  203. color: "#000000",
  204. marginHorizontal: 12
  205. },
  206. TagButtonBgView: {
  207. width: ScreenDimensions.width,
  208. height: 45,
  209. marginTop: 8,
  210. borderBottomColor: '#efeff4',
  211. borderBottomWidth: 0.5,
  212. backgroundColor: 'white',
  213. flexDirection: 'row',
  214. alignItems: 'center',
  215. },
  216. TagButtonView: {
  217. height: 45,
  218. justifyContent: 'center',
  219. alignItems: 'center',
  220. borderBottomColor: 'white',
  221. },
  222. TagButtonTitle: {
  223. fontSize: 16,
  224. marginRight: 36,
  225. color: "#666666"
  226. }
  227. });