1.卡片滑动切歌react
2.显示进度条git
1.react-native-videogithub
Github地址:https://github.com/react-native-community/react-native-videonpm
2.react-native-animated-tabsreact-native
Github地址:https://github.com/philipshurpik/react-native-animated-tabsapp
Using npm:ide
npm install --save react-native-video npm install --save react-native-animated-tabs
or using yarn:函数
yarn add react-native-video yarn add react-native-animated-tabs
若是RN版本>=0.60,是自动link的,若是在0.60如下则须要手动linkui
运行 `react-native link react-native-video` 链接react-native-video库 react-native-animated-tabs同上
import AnimatedTabs from "react-native-animated-tabs";
<AnimatedTabs panelWidth={getPanelWidth()} activePanel={this.state.activePanel} onAnimateFinish={activePanel => this.setState({ activePanel })} > /** 此处放你的卡片 <View><Image source={...}/></View> ... */ </AnimatedTabs>
<View style={styles.buttons}> <TouchableOpacity style={styles.text} onPress={() => this.goToPanel(-1)} > <Text>上一首歌</Text> </TouchableOpacity> <TouchableOpacity style={styles.text} onPress={() => this.goToPanel(1)} > <Text>下一首歌</Text> </TouchableOpacity>
goToPanel(direction) { const nextPanel = this.state.activePanel + direction; if (nextPanel >= 0 && nextPanel < panelsCount) { this.setState({ activePanel: nextPanel }); } } }
这时候就能够实现滑动卡片功能了this
import Video from "react-native-video"; import url1 from "../static/video/徐小明-渔歌.mp3";
<Video source={require('./background.mp4')} // 视频的URL地址,或者本地地址 //source={require('./music.mp3')} // 能够播放音频 //source={{uri:'http://......'}} ref='player' rate={this.state.isPlay?1:0} // 控制暂停/播放,0 表明暂停paused, 1表明播放normal. volume={1.0} // 声音的放声音的放大倍数大倍数,0 为静音 ,1 为正常音量 ,更大的数字表示放大的倍数 muted={false} // true表明静音,默认为false. paused={false} // true表明暂停,默认为false resizeMode="contain" // 视频的自适应伸缩铺放行为,contain、stretch、cover repeat={false} // 是否重复播放 playInBackground={false} // 当app转到后台运行的时候,播放是否暂停 playWhenInactive={false} // [iOS] Video continues to play when control or notification center are shown. 仅适用于IOS onLoadStart={this.loadStart} // 当视频开始加载时的回调函数 onLoad={this.setDuration} // 当视频加载完毕时的回调函数 onProgress={this.setTime} // 进度控制,每250ms调用一次,以获取视频播放的进度 onEnd={this.onEnd} // 当视频播放完毕后的回调函数 onError={this.videoError} // 当视频不能加载,或出错后的回调函数 style={styles.backgroundVideo} />
<Video ref={video => (this.player = video)} source={SONGS[this.state.activePanel].url} ref="video" paused={this.state.paused} onLoad={data => this.setDuration(data)} volume={1.0} paused={false} onEnd={() => this.goToPanel(1)} playInBackground={true} onProgress={e => this.setTime(e)} playWhenInactive={true} />
constructor() { super(); this.state = { activePanel: 0, //当前active的面板 activeSong: SONGS[0], //正在播放的歌 currentTime: 0.0, //当前播放的时间 paused: 1.0, //播放 sliderValue: 0, //进度条的进度 duration: 0.0 //总时长 }; } //格式化音乐播放的时间为0:00 formatMediaTime(duration) { let min = Math.floor(duration / 60); let second = duration - min * 60; min = min >= 10 ? min : "0" + min; second = second >= 10 ? second : "0" + second; return min + ":" + second; } //设置进度条和播放时间的变化 setTime(data) { let sliderValue = parseInt(this.state.currentTime); this.setState({ slideValue: sliderValue, currentTime: data.currentTime }); } //设置总时长 setDuration(duration) { this.setState({ duration: duration.duration }); }
<Slider style={styles.slider} value={this.state.slideValue} maximumValue={this.state.duration} step={1} onValueChange={value => this.setState({ currentTime: value })} />