Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
1.5 kB
1
Indexable
Never
 const play = async (song) => {
        try {
            const play_object = audioContext.get_play_object();
            const {isLoaded} = await play_object.getStatusAsync();
            if (isLoaded) {
                const context_song = await audioContext.get_song();
                if (context_song.id === song.id) {
                    (icon === "playcircleo") ? play_music() : pause_music();
                }else {
                    await play_object.pauseAsync();
                    await play_object.unloadAsync();
                    await play_object.loadAsync(
                        {
                            uri: song.file.path,
                        }, 
                        {
                            shouldPlay: true,
                        }
                    )
                    await audioContext.set_song(song);
                    setIcon("pausecircleo");
                }
            }else {
                await play_object.loadAsync(
                    {
                        uri: song.file.path,
                    }, 
                    {
                        shouldPlay: true,
                    }
                )
                await audioContext.set_song(song);
                setIcon("pausecircleo");
                navigation.navigate("ArtistSection", {Songinfo: song, duration: duration, durationMillis: durationMillis});
            }
        }catch(error) {
            console.log(error);
        }
    }