Skip to content

Commit ab81dda

Browse files
committed
fix: refactor of player component
1 parent 3b44bd0 commit ab81dda

File tree

1 file changed

+34
-28
lines changed

1 file changed

+34
-28
lines changed

app/redux/modules/player.js

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,42 @@ import Immutable from 'immutable';
44
import {NativeModules} from 'react-native';
55
const {BackgroundPlayer} = NativeModules;
66

7-
export const toggleButton = () => (
8-
(dispatch, getState) => {
9-
const {player} = getState()
10-
const mode = player.get('mode');
7+
const demoTracks = [
8+
{
9+
artist: "Swervedriver",
10+
title: "99th dream",
11+
uri: "https://psv4.vk.me/c1814/u602240/audios/3c1285bc0568.mp3?extra=lFM15JAWy028kJhacDc9g3hewp6cyScRXnaMDoSXQ4JFalIc6ehimXvykXUNIRe5VkfVNeZZbbRlFkGc2cd-e32ygjorxMQ"
12+
},
13+
{
14+
artist: "Papa Roach",
15+
title: "The World Around You (The Paramour Sessions)",
16+
uri: "https://cs1-37v4.vk-cdn.net/p9/cea92d23d89fe2.mp3?extra=H7-AMY7mfBo4h1Z3kDGHwCvjuTKx-H1HBNXMqvn2B5km8kRwufqmRlk2ymxb_tVZwuwglFswTYIG5AaQXlJ2_y670KpY3Ac"
17+
}
18+
]
19+
20+
export const toggleButton = () =>
21+
(dispatch, getState) => {
22+
const {player} = getState()
23+
switch (player.get('mode')) {
24+
case 'paused':
25+
BackgroundPlayer.play()
26+
return dispatch(createAction('ET_PLAYER_STATE')({mode: 'playing'}));
27+
case 'stopped':
28+
BackgroundPlayer.setTrackList(demoTracks);
1129

12-
let newMode;
13-
if(mode === 'paused') {
14-
BackgroundPlayer.play()
15-
newMode = 'playing';
16-
} else if(mode === 'stopped') {
17-
BackgroundPlayer.setTrackList([
18-
{artist: "Swervedriver", title: "99th dream", uri: "https://psv4.vk.me/c1814/u602240/audios/3c1285bc0568.mp3?extra=lFM15JAWy028kJhacDc9g3hewp6cyScRXnaMDoSXQ4JFalIc6ehimXvykXUNIRe5VkfVNeZZbbRlFkGc2cd-e32ygjorxMQ"},
19-
{artist: "Papa Roach", title: "The World Around You (The Paramour Sessions)", uri: "https://cs1-37v4.vk-cdn.net/p9/cea92d23d89fe2.mp3?extra=H7-AMY7mfBo4h1Z3kDGHwCvjuTKx-H1HBNXMqvn2B5km8kRwufqmRlk2ymxb_tVZwuwglFswTYIG5AaQXlJ2_y670KpY3Ac"}
20-
]);
21-
22-
BackgroundPlayer.setNextTrack();
23-
BackgroundPlayer.play()
30+
BackgroundPlayer.setNextTrack();
31+
BackgroundPlayer.play()
32+
33+
return dispatch(createAction('ET_PLAYER_STATE')({mode: 'playing'}));
34+
default:
35+
BackgroundPlayer.pause()
36+
return dispatch(createAction('ET_PLAYER_STATE')({mode: 'paused'}));
37+
}
2438

25-
dispatch(createAction('SET_PLAYER_STATE')({mode: 'playing'}));
26-
} else {
27-
BackgroundPlayer.pause()
28-
newMode = 'paused';
2939
}
30-
31-
dispatch(createAction('SET_PLAYER_STATE')({mode: newMode}));
32-
}
33-
)
40+
3441

3542
export default handleActions({
36-
'SET_PLAYER_STATE': (state, {payload:{mode}})=> state.set('mode', mode)
37-
},
38-
Immutable.fromJS({mode: 'stopped'})
39-
)
43+
'SET_PLAYER_STATE': (state, {payload:{mode}})=> state.set('mode', mode)
44+
},
45+
Immutable.fromJS({mode: 'stopped'}))

0 commit comments

Comments
 (0)