React Native Cookbook
上QQ阅读APP看书,第一时间看更新

Creating an audio player

Audio players are another common interface built into many applications. Whether your app needs to play audio files stored locally on the device or stream audio from a remote location, Expo's Audio component comes to the rescue.

In this recipe, we'll be building a full-fledged basic audio player, with play/pause, next track, and previous track functionality. For simplicity, we'll be hardcoding the information for the tracks we'll be using, but in a real-world scenario, you'll likely be working with similar objects to what we're defining: an object with a track title, album name, artist name, and a URL to a remote audio file. I've chosen three random live tracks from the Internet Archive's Live Music Archive (https://archive.org/details/etree).