Skip to content

Commit 1afffa2

Browse files
committed
added showing a counter
1 parent dd6b97b commit 1afffa2

File tree

3 files changed

+86
-45
lines changed

3 files changed

+86
-45
lines changed

App/Containers/MusicPlayerScreen.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,22 @@ class MusicPlayer extends React.Component {
1111
super(props)
1212
this.state = {
1313
searchTerm: '',
14-
currentlyDisplayed: []
14+
currentlyDisplayed: [],
15+
selectedGenres: []
1516
}
1617
}
1718
componentWillReceiveProps (props) {
18-
this.setState({currentlyDisplayed: props.songs})
19+
this.setState({currentlyDisplayed: props.songs, selectedGenres: props.genres})
1920
}
2021
filterDisplayed (text) {
2122
const songContains = (a, p) => R.path(['metadata', p], a).toLowerCase().indexOf(text.toLowerCase()) > -1
22-
const currentlyDisplayed = this.props.songs
23+
let currentlyDisplayed = this.props.songs
2324
.filter(song =>
2425
songContains(song, 'title') ||
2526
songContains(song, 'artist') ||
2627
songContains(song, 'genre')
2728
)
28-
this.setState({currentlyDisplayed})
29+
this.setState({currentlyDisplayed: currentlyDisplayed.filter(song => R.contains(song.genre, this.state.selectedGenres))})
2930
}
3031
render () {
3132
const songs = this.state.currentlyDisplayed || []
@@ -40,8 +41,8 @@ class MusicPlayer extends React.Component {
4041
}
4142

4243
const mapStateToProps = (state) => {
43-
const { songs = [] } = state.songs
44-
return { songs }
44+
const { songs = [], genres = [] } = state.songs
45+
return { songs, genres }
4546
}
4647

4748
const mapDispatchToProps = (dispatch) => {

App/Containers/PlayerArea.js

+69-36
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,77 @@ const textStyle = {
1111
color: Colors.snow
1212
}
1313

14-
const PlayerArea = ({ playing, play, pause, stop, metadata }) => (
15-
<View>
16-
<View style={styles.container}>
17-
<View style={{flexDirection: 'column', alignItems: 'flex-start', justifyContent: 'flex-start', paddingBottom: 20}}>
18-
<Text style={textStyle}>
19-
{metadata && metadata.title}
20-
</Text>
21-
<Text style={textStyle}>
22-
{metadata && metadata.artist}
23-
</Text>
24-
</View>
25-
</View>
26-
<TouchableOpacity
27-
activeOpacity={1.0}
28-
style={styles.delayedstart}
29-
onPress={() => setTimeout(play, 2000)}
30-
>
31-
{ playing
32-
? <View />
33-
: <Icon size={30} name={'play-circle-o'} color='#fff' />
14+
class PlayerArea extends React.Component {
15+
constructor (props) {
16+
super(props)
17+
this.state = {
18+
count: 5,
19+
counting: false
20+
}
21+
}
22+
componentDidMount () {
23+
const intervalId = setInterval(() => this.timer(), 1000)
24+
this.setState({intervalId: intervalId})
25+
}
26+
componentWillUnmount () {
27+
clearInterval(this.state.intervalId)
28+
}
29+
30+
timer = () => {
31+
const {count, counting} = this.state
32+
if (counting) {
33+
let newCount = count - 1
34+
if (newCount === 0) {
35+
this.props.play()
36+
this.setState({count: 5, counting: false})
37+
} else {
38+
this.setState({count: newCount})
3439
}
35-
</TouchableOpacity>
36-
<TouchableOpacity
37-
activeOpacity={1.0}
38-
onPress={playing ? pause : play}
39-
style={styles.playpause}
40+
}
41+
}
42+
render () {
43+
const { playing, play, pause, stop, metadata } = this.props
44+
const { count } = this.state
45+
return (
46+
<View>
47+
<View style={styles.container}>
48+
<View style={{flexDirection: 'column', alignItems: 'flex-start', justifyContent: 'flex-start', paddingBottom: 20}}>
49+
<Text style={textStyle}>
50+
{metadata && metadata.title}
51+
</Text>
52+
<Text style={textStyle}>
53+
{metadata && metadata.artist}
54+
</Text>
55+
</View>
56+
</View>
57+
<TouchableOpacity
58+
activeOpacity={1.0}
59+
style={styles.delayedstart}
60+
onPress={() => this.setState({counting: true})}
61+
>
62+
{ count !== 5
63+
? <Text style={{fontSize: 30, color: 'white'}}>{count}</Text>
64+
: <Icon size={30} name={'play-circle-o'} color={playing ? 'rgba(0, 0, 0, 0)' : '#fff'} />
65+
}
66+
</TouchableOpacity>
67+
<TouchableOpacity
68+
activeOpacity={1.0}
69+
onPress={playing ? pause : play}
70+
style={styles.playpause}
71+
>
72+
<Icon size={30} name={playing ? 'pause' : 'play'} color='#fff' />
73+
</TouchableOpacity>
74+
<TouchableOpacity
75+
playing={playing}
76+
onPress={stop}
77+
style={styles.stop}
4078
>
41-
<Icon size={30} name={playing ? 'pause' : 'play'} color='#fff' />
42-
</TouchableOpacity>
43-
<TouchableOpacity
44-
playing={playing}
45-
onPress={stop}
46-
style={styles.stop}
47-
>
48-
<Icon size={30} name='stop' color='#fff' />
49-
</TouchableOpacity>
50-
</View>
51-
)
79+
<Icon size={30} name='stop' color='#fff' />
80+
</TouchableOpacity>
81+
</View>
82+
)
83+
}
84+
}
5285

5386
const mapStateToProps = ({player}) => {
5487
const {file, metadata, playing} = player

App/Sagas/SonglistSagas.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,15 @@ async function getAllFiles (allDirectories, allFiles) {
4040
async function addMetadata (allFiles, resultMetadata) {
4141
for (let i = 0; i < allFiles.length; i++) {
4242
const file = allFiles[i]
43-
const metadata = await MediaMeta.get(file)
44-
if (metadata) {
45-
resultMetadata.push({file, metadata})
43+
try {
44+
const metadata = await MediaMeta.get(file)
45+
if (metadata) {
46+
resultMetadata.push({file, metadata})
47+
}
48+
} catch (err) {
49+
console.tron.display({
50+
name: `FAILED TO READ FILE: ${file}`
51+
})
4652
}
4753
}
4854
}
@@ -52,6 +58,7 @@ export function * scanFiles (action) {
5258
const allfiles = []
5359
const allMeta = []
5460
try {
61+
// check the folders exist
5562
yield call(getFoldersRecursive, MEDIA_DIR, all)
5663
yield call(getAllFiles, all, allfiles)
5764
yield call(addMetadata, allfiles, allMeta)

0 commit comments

Comments
 (0)