-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathApp.js
More file actions
98 lines (89 loc) · 2.17 KB
/
App.js
File metadata and controls
98 lines (89 loc) · 2.17 KB
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
import React, {useEffect} from 'react';
import TrackPlayer from 'react-native-track-player';
import {StyleSheet, View, TouchableOpacity, Text} from 'react-native';
const tracks = [
{
id: 1,
url: require('./tracks/blues.wav'),
title: 'Blues Beat',
},
{
id: 2,
url: require('./tracks/country.mp3'),
title: 'Blues Beat',
},
];
TrackPlayer.updateOptions({
stopWithApp: false,
capabilities: [TrackPlayer.CAPABILITY_PLAY, TrackPlayer.CAPABILITY_PAUSE],
compactCapabilities: [
TrackPlayer.CAPABILITY_PLAY,
TrackPlayer.CAPABILITY_PAUSE,
],
});
const App = () => {
const setUpTrackPlayer = async () => {
try {
await TrackPlayer.setupPlayer();
await TrackPlayer.add(tracks);
console.log('Tracks added');
} catch (e) {
console.log(e);
}
};
useEffect(() => {
setUpTrackPlayer();
return () => TrackPlayer.destroy();
}, []);
return (
<View style={styles.container}>
<View style={styles.row}>
<TouchableOpacity
style={styles.btn}
onPress={() => TrackPlayer.pause()}>
<Text style={styles.text}>Pause</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.btn} onPress={() => TrackPlayer.play()}>
<Text style={styles.text}>Play</Text>
</TouchableOpacity>
</View>
<View style={styles.row}>
<TouchableOpacity
style={styles.btn}
onPress={() => TrackPlayer.skipToPrevious()}>
<Text style={styles.text}>Prev</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.btn}
onPress={() => TrackPlayer.skipToNext()}>
<Text style={styles.text}>Next</Text>
</TouchableOpacity>
</View>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'black',
},
btn: {
backgroundColor: '#ff0044',
padding: 15,
borderRadius: 10,
margin: 10,
width: 160,
},
text: {
fontSize: 30,
color: 'white',
textAlign: 'center',
},
row: {
flexDirection: 'row',
marginBottom: 20,
},
});
export default App;