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 })} />