No Description

ShortVideoCellView.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. /**
  2. * Created by zack on 2018/4/19.
  3. */
  4. import {
  5. View,
  6. Text,
  7. Image,
  8. StyleSheet,
  9. TouchableHighlight,
  10. ImageBackground
  11. } from 'react-native'
  12. import React, { Component } from 'react'
  13. import ScreenDimensions from '../../../utils/ScreenDimensions'
  14. import ScreenDimensionsClientHeight from '../../../utils/ScreenDimensions'
  15. import NavigationBarHeight from '../../../utils/NavigationBarHeight'
  16. import TabBarHeight from '../../../utils/TabBarHeight'
  17. import RefreshInfiniteListView from '../../../utils/RefreshInfiniteListView'
  18. import Video from 'react-native-video'
  19. import ShortVideoProgressView from "./ShortVideoProgressView"
  20. import ShortVideoEndView from "./ShortVideoEndView"
  21. //ScreenDimensions.clientHeight
  22. export default class VideoDetailsCellViewContorller extends Component {
  23. constructor(props) {
  24. super(props)
  25. this.state = {
  26. showMp: true,
  27. rate: false,//播放数据
  28. showBtn: true,//进入 显示播放 按钮
  29. endBoolPlay: true,
  30. paused:false,//是否重新播放
  31. }
  32. }
  33. componentDidMount() {
  34. }
  35. componentWillReceiveProps(nextProps) {
  36. if (nextProps.selectedPages != this.props.selectedPages) {
  37. this.setState({
  38. rate: nextProps.selectedPages
  39. })
  40. }
  41. }
  42. render() {
  43. let playIcon = require('../../../resources/images/TabBar/Community/ShortVideo/play.png');
  44. let bottomBackground = require('../../../resources/images/TabBar/Community/ShortVideo/bg_01.png');
  45. let likeIcon = require('../../../resources/images/TabBar/Community/ShortVideo/like.png');
  46. let messIcon = require('../../../resources/images/TabBar/Community/ShortVideo/mess.png');
  47. let moreIcon = require('../../../resources/images/TabBar/Community/ShortVideo/more.png');
  48. let userIcon = require('../../../resources/images/TabBar/Community/ShortVideo/user1.png');
  49. let followIcon = require('../../../resources/images/TabBar/Community/ShortVideo/follow.png');
  50. let suspendedIcon = require('../../../resources/images/TabBar/Community/ShortVideo/suspend.png');
  51. return (
  52. <View
  53. style={styles.View}>
  54. <Video ref={(ref) => {
  55. this.video = ref
  56. }}
  57. source={require('../../../resources/MP4/2.mp4')}
  58. style={styles.fullScreen}
  59. rate={this.state.rate ? 1 : 0} // 控制暂停/播放,0 代表暂停paused, 1代表播放normal.
  60. paused={this.state.paused}
  61. volume={1} // 声音的放大倍数,0 代表没有声音,就是静音muted, 1 代表正常音量 normal,更大的数字表示放大的倍数
  62. muted={true} // true代表静音,默认为false.
  63. resizeMode='cover' // 视频的自适应伸缩铺放行为,
  64. onLoad={this.onLoad.bind(this)} // 当视频加载完毕时的回调函数
  65. onLoadStart={this.loadStart.bind(this)} // 当视频开始加载时的回调函数
  66. onProgress={this.onProgress.bind(this)} // 进度控制,每250ms调用一次,以获取视频播放的进度
  67. onEnd={this.onEnd.bind(this)} // 当视频播放完毕后的回调函数
  68. onError={this.videoError.bind(this)} // 当视频不能加载,或出错后的回调函数
  69. onAudioBecomingNoisy={this.onAudioBecomingNoisy.bind(this)}
  70. onAudioFocusChanged={this.onAudioFocusChanged.bind(this)}
  71. repeat={true} // 是否重复播放
  72. onBuffer={this.onBuffer}
  73. />
  74. {/* {this.state.showMp ? <View style={styles.fullScreen}>
  75. <Image source={require('../../../resources/images/TabBar/Community/SmallVideo/VideoDetails/bg.png')} style={styles.loadingStyle} />
  76. </View> : undefined} */}
  77. {this.state.endBoolPlay ? <View style={styles.aboveStyle}>
  78. <TouchableHighlight
  79. underlayColor={"rgba(255,255,255,0)"}
  80. onPress={this.onPressPlay.bind(this)}>
  81. <View style={styles.topVideo}>
  82. {this.state.showBtn ? <Image source={playIcon} style={styles.playStyle} /> : undefined}
  83. {/* {!this.state.rate&&!this.state.showBtn 这个状态代表播放中 反之暂停中} */}
  84. {!this.state.rate && !this.state.showBtn ? <Image source={suspendedIcon} style={styles.suspendedStyle} /> : undefined}
  85. </View>
  86. </TouchableHighlight>
  87. <View style={styles.userViewStyle}>
  88. <ImageBackground source={bottomBackground} style={styles.bottomStyle}>
  89. {this.state.rate ?
  90. <ShortVideoProgressView ref={(r) => {
  91. this.progressView = r
  92. }} totalText={"03:00"} fullScreen={this.callfullScreen.bind(this)} />
  93. :
  94. <View style={styles.playBeforeStyle}>
  95. <View style={styles.bottomLeftStyle}>
  96. <View style={styles.headImage}>
  97. <View style={styles.headStyle}>
  98. <Image source={userIcon} style={styles.userIcon} />
  99. </View>
  100. <Image source={followIcon} style={styles.followStyle} />
  101. </View>
  102. <Text style={styles.nameStyle}>{"hhaha"}</Text>
  103. </View>
  104. <View style={styles.bottomRightStyle}>
  105. <View style={styles.textView}>
  106. <Text style={styles.numberStyle}>{"01:44"}</Text>
  107. </View>
  108. </View>
  109. </View>
  110. }
  111. </ImageBackground>
  112. </View>
  113. </View> :
  114. <ShortVideoEndView replay={this.replay.bind(this)} />
  115. }
  116. <View style={styles.toolStyle}>
  117. <View style={styles.leftToolStyle}>
  118. <Text numberOfLines={10} style={styles.toolTextStyle}>{"钟记住100个单侧"}</Text>
  119. </View>
  120. <View style={styles.rightToolStyle}>
  121. <TouchableHighlight
  122. underlayColor={"rgba(255,255,255,0)"}
  123. onPress={this.onPresslike.bind(this)}>
  124. <View style={styles.childrenView}>
  125. <Image source={likeIcon} style={styles.likeIcon} />
  126. <Text style={styles.textStyle}>688</Text>
  127. </View>
  128. </TouchableHighlight>
  129. <TouchableHighlight
  130. underlayColor={"rgba(255,255,255,0)"}
  131. onPress={this.onPressForMess.bind(this)}>
  132. <View style={styles.childrenView}>
  133. <Image source={messIcon} style={styles.messIcon} />
  134. <Text style={styles.textStyle}>688</Text>
  135. </View>
  136. </TouchableHighlight>
  137. <TouchableHighlight
  138. underlayColor={"rgba(255,255,255,0)"}
  139. onPress={this.onPressShare.bind(this)}>
  140. <View style={styles.childrenView}>
  141. <Image source={moreIcon} style={styles.moreIcon} />
  142. </View>
  143. </TouchableHighlight>
  144. </View>
  145. </View>
  146. </View>
  147. );
  148. }
  149. //-------------------
  150. onPresslike() {
  151. //点赞
  152. }
  153. onPressForMess() {
  154. //评论
  155. }
  156. onPressShare() {
  157. //分享
  158. }
  159. callfullScreen() {
  160. //全屏
  161. this.video.presentFullscreenPlayer()
  162. }
  163. loadStart() {
  164. //需要 添加背景图片
  165. console.log("loadStart=======")
  166. }
  167. onProgress(time) {
  168. if (!this.state.paused&&this.state.rate) {
  169. let progressValue = time.currentTime / time.seekableDuration
  170. this.progressView.setProgressValue(progressValue, time.currentTime)
  171. }
  172. }
  173. onEnd() {
  174. this.setState({
  175. endBoolPlay: false,
  176. paused:true
  177. })
  178. }
  179. onError() {
  180. console.log("onError=======")
  181. }
  182. onAudioBecomingNoisy() {
  183. }
  184. onAudioFocusChanged() {
  185. }
  186. onLoad() {
  187. console.log("当视频加载完毕时的回调函数")
  188. this.setState({
  189. showMp: false
  190. })
  191. }
  192. videoError() {
  193. }
  194. onPressInput() {
  195. this.refs.chatInputBar.openInputBar();
  196. }
  197. _onSendMsg(text) {
  198. }
  199. onBuffer() {
  200. }
  201. onPressPlay() {
  202. //暂停 播放
  203. let rate = this.state.rate;
  204. let showBtn = this.state.showBtn;
  205. this.setState({
  206. rate: !rate,
  207. showBtn: false
  208. })
  209. }
  210. //播放完成 分享按钮事件
  211. onPressChat() {
  212. }
  213. onPressChatFirend() {
  214. }
  215. onPressQQ() {
  216. }
  217. onPressSina() {
  218. }
  219. replay() {
  220. this.setState({
  221. paused: false,
  222. endBoolPlay: true,
  223. })
  224. }
  225. }
  226. const styles = StyleSheet.create({
  227. View: {
  228. width: ScreenDimensions.width,
  229. height: ScreenDimensions.height,
  230. },
  231. fullScreen: {
  232. width: ScreenDimensions.width,
  233. height: 195,
  234. },
  235. loadingStyle: {
  236. position: 'absolute',
  237. top: -ScreenDimensions.height,
  238. left: 0,
  239. bottom: 0,
  240. right: 0,
  241. },
  242. aboveStyle: {
  243. marginTop: -195,
  244. // backgroundColor:"yellow"
  245. },
  246. topVideo: {
  247. width: ScreenDimensions.width,
  248. height: 100,
  249. // opacity: 0,
  250. // justifyContent: "center",
  251. paddingTop: 50,
  252. alignItems: "center"
  253. },
  254. playStyle: {
  255. width: 40,
  256. height: 40
  257. },
  258. suspendedStyle: {
  259. width: 30,
  260. height: 30,
  261. },
  262. userViewStyle: {
  263. width: ScreenDimensions.width,
  264. height: 195 - 150 + 50,
  265. justifyContent: "space-between"
  266. },
  267. // 播放中 与 播放时 的 style
  268. bottomStyle: {
  269. // justifyContent: "space-between",
  270. flexDirection: "row",
  271. marginBottom: 10,
  272. height: 95,
  273. paddingTop: 30,
  274. },
  275. bottomLeftStyle: {
  276. // flex: 1,
  277. alignItems: "center",
  278. flexDirection: "row",
  279. },
  280. nameStyle: {
  281. fontSize: 14,
  282. color: "#ffffff",
  283. marginLeft: 15
  284. },
  285. headImage: {
  286. flexDirection: "row"
  287. },
  288. userIcon: {
  289. width: 40,
  290. height: 40,
  291. },
  292. headStyle: {
  293. width: 42,
  294. height: 42,
  295. borderRadius: 42,
  296. justifyContent: "center",
  297. alignItems: "center",
  298. backgroundColor: "#ffffff",
  299. marginLeft: 11,
  300. },
  301. followStyle: {
  302. width: 12,
  303. height: 12,
  304. marginTop: 30,
  305. marginLeft: -15
  306. },
  307. bottomRightStyle: {
  308. // flex: 1,
  309. alignItems: "flex-end",
  310. justifyContent: "center"
  311. },
  312. textView: {
  313. backgroundColor: "gray",
  314. borderRadius: 10,
  315. width: 60,
  316. height: 20,
  317. justifyContent: "center",
  318. alignItems: "center",
  319. marginRight: 12
  320. },
  321. toolStyle: {
  322. width: ScreenDimensions.width,
  323. height: 58,
  324. backgroundColor: "#ffffff",
  325. flexDirection: "row"
  326. },
  327. leftToolStyle: {
  328. flex: 1,
  329. paddingTop: 16,
  330. // justifyContent:"center",
  331. alignItems: "center"
  332. },
  333. rightToolStyle: {
  334. flex: 1,
  335. flexDirection: "row",
  336. alignItems: "center",
  337. // paddingTop: 16,
  338. justifyContent: "flex-end"
  339. },
  340. toolTextStyle: {
  341. fontSize: 18,
  342. color: "#000000",
  343. marginHorizontal: 12
  344. },
  345. likeIcon: {
  346. width: 38 / 2,
  347. height: 35 / 2
  348. },
  349. textStyle: {
  350. marginHorizontal: 10
  351. },
  352. messIcon: {
  353. width: 38 / 2,
  354. height: 38 / 2
  355. },
  356. moreIcon: {
  357. width: 31 / 2,
  358. height: 6 / 2,
  359. marginRight: 12
  360. },
  361. childrenView: {
  362. alignItems: "center",
  363. flexDirection: "row"
  364. },
  365. playBeforeStyle: {
  366. justifyContent: "space-between",
  367. flexDirection: "row",
  368. width: ScreenDimensions.width,
  369. },
  370. })