@@ -11,44 +11,77 @@ const textStyle = {
11
11
color : Colors . snow
12
12
}
13
13
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 } )
34
39
}
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 }
40
78
>
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
+ }
52
85
53
86
const mapStateToProps = ( { player} ) => {
54
87
const { file, metadata, playing} = player
0 commit comments