-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
executable file
·171 lines (165 loc) · 4.72 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import React, {Component} from 'react';
import {
View,
Text,
ScrollView,
Image,
TouchableOpacity,
TextInput,
FlatList,
} from 'react-native';
import Axios from 'axios';
import SoundPlayer from 'react-native-sound-player';
import Icon from 'react-native-vector-icons/FontAwesome';
import base64 from 'react-native-base64';
import ContentLoader from 'react-native-easy-content-loader';
import OrientationLoadingOverlay from 'react-native-orientation-loading-overlay';
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
dataLagu: [],
isPlaying: false,
keyword: '',
DataCari: [],
LoadingSearch: false,
LoadingPlay: false,
};
}
LoadMusic = url => {
this.setState({
isPlaying: false,
LoadingPlay: true,
});
SoundPlayer.stop();
Axios.post(`http://api.kitabuat.com/jooy/song/`, {
id: url,
}).then(result => {
this.setState({
dataLagu: result.data,
});
SoundPlayer.loadUrl(result.data.mp3Url);
SoundPlayer.addEventListener('FinishedLoadingURL', ({success, url}) => {
SoundPlayer.play();
this.setState({isPlaying: true, LoadingPlay: false});
SoundPlayer.addEventListener('FinishedPlaying', ({success}) => {
this.setState({isPlaying: false});
});
});
});
};
PlayMusic = () => {
if (this.state.isPlaying === true) {
this.setState({isPlaying: false});
SoundPlayer.pause();
} else {
this.setState({isPlaying: true});
SoundPlayer.play();
}
};
handleChange = key => val => {
this.setState({[key]: val});
};
_search = async () => {
this.setState({LoadingSearch: true});
Axios.post(`http://api.kitabuat.com/jooy/search_song/`, {
id: this.state.keyword,
}).then(result => {
this.setState({
DataCari: result.data.itemlist,
LoadingSearch: false,
});
});
};
render() {
return (
<View style={{flex: 1, backgroundColor: '#373C3F'}}>
<OrientationLoadingOverlay
visible={this.state.LoadingPlay}
color="white"
indicatorSize="large"
messageFontSize={14}
message="Loading Song..."
/>
<View
style={{
backgroundColor: '#95898E',
flexDirection: 'row',
justifyContent: 'space-between',
borderRadius: 20,
height: 50,
marginHorizontal: 10,
marginTop: 5,
}}>
<TextInput
placeholder="Search"
placeholderTextColor="#F6F5F6"
style={{
paddingLeft: 50,
paddingRight: 10,
color: 'white',
padding: 10,
position: 'relative',
}}
onChangeText={this.handleChange('keyword')}
value={this.state.keyword}
onSubmitEditing={this._search}
/>
<Icon
name="search"
style={{
position: 'absolute',
top: 10,
left: 15,
}}
size={25}
color="white"
/>
</View>
<ScrollView style={{flex: 1, marginTop: 20, marginHorizontal: 30}}>
<ContentLoader
loading={this.state.LoadingSearch}
animationDuration={500}
active
pRows={1}
listSize={2}
pHeight={[20, 30, 100]}>
<FlatList
data={this.state.DataCari}
keyExtractor={(item, index) => index.toString()}
renderItem={({item}) => (
<TouchableOpacity
style={{marginBottom: 25}}
onPress={() => this.LoadMusic(base64.encode(item.songid))}>
<Text style={{color: '#F6F5F6', fontSize: 18}}>
{base64.decode(item.info1)}
</Text>
<Text style={{color: '#F6F5F6', fontSize: 16}}>
{base64.decode(item.info2)}
</Text>
</TouchableOpacity>
)}
/>
</ContentLoader>
</ScrollView>
<View
style={{
height: 70,
backgroundColor: '#18D1A8',
flexDirection: 'row',
}}>
<View
style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
<TouchableOpacity onPress={this.PlayMusic}>
{this.state.isPlaying ? (
<Icon name="pause" size={30} color="white" />
) : (
<Icon name="play" size={30} color="white" />
)}
</TouchableOpacity>
</View>
</View>
</View>
);
}
}