-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
94 lines (87 loc) · 2.28 KB
/
App.tsx
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
import '@expo/metro-runtime';
import {
SafeAreaView,
StatusBar,
StyleSheet,
Text,
View,
useWindowDimensions,
} from 'react-native';
import TrackPlayer, { Track } from 'react-native-track-player';
import { useState, useEffect } from 'react';
import AlbumArt from './src/components/AlbumArt';
import { MEDIA_QUERY_BREAKPOINT_PX } from './src/utils';
import Playlist from './src/components/composites/Playlist';
import Header from './src/components/composites/Header';
import { sampleSongData } from './src/utils';
export default function App() {
const { width } = useWindowDimensions();
const [info, setInfo] = useState<Track>();
const [queue, setQueue] = useState<Track[]>([]);
const [currentTrack, setCurrentTrack] = useState(0);
async function loadPlaylist() {
const queue = await TrackPlayer.getQueue();
setQueue(queue);
}
async function setTrackInfo() {
const track = await TrackPlayer.getActiveTrack();
setInfo(track);
}
useEffect(() => {
async function setup() {
try {
await TrackPlayer.setupPlayer();
const queue = await TrackPlayer.getQueue();
if (queue.length <= 0) {
await TrackPlayer.add(sampleSongData);
setTrackInfo();
loadPlaylist();
}
} catch (err) {
console.error('Media player setup failed: ', err);
}
}
setup();
}, []);
return (
<SafeAreaView style={[{ flex: 1, backgroundColor: '#eee' }]}>
<StatusBar
animated={true}
backgroundColor='#999'
hidden={false}
/>
<View
style={[
styles.container,
width > MEDIA_QUERY_BREAKPOINT_PX
? styles.flexRow
: styles.flexColumn,
]}
>
<Header {...{ width, info, setInfo, setCurrentTrack, setQueue }} />
<Text>{'\n'}</Text>
</View>
<AlbumArt
{...{
width,
album: info?.album,
artworkUri: info?.artwork,
artist: info?.artist,
}}
/>
<Playlist {...{ queue, currentTrack, setInfo, setCurrentTrack }} />
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
backgroundColor: '#eee',
height: 60,
},
flexRow: {
flexDirection: 'row',
},
flexColumn: {
flexDirection: 'column',
},
});