Build an Audio Player
by Eric Portis
Now that we have an endpoint, let’s use it to build a streaming audio player.
Step 1: Get the data
First, let’s get data from our endpoint, and into a browser.
See the Pen Streaming Audio Player, Step 1: Get the data by Eric Portis (@eeeps) on CodePen.
Step 2: Set up a bunch of boilerplate
Before we can do anything, we’ll need to initialize our video player stack.
For this tutorial, we’'ll be using VideoJS, and its excellent playlist plugin and playlist-ui picker.
Here’s all of the boilerplate we’ll need to load all of those components:
See the Pen Streaming Audio Player, Step 2: Set up a bunch of boilerplate by Eric Portis (@eeeps) on CodePen.
(I’ll tuck all of that into our pen’s settings, for our next and last example.)
Step 3: Data + boilerplate = a player!
Our player expects a playlist array that looks like this.
So, what we need to do is:
map the returned data from our endpoint, into an array that looks like that
feed it to our player using the
player.playlist()
methodbuild the playlist UI, using the
player.playlistUi()
method.
Like this:
See the Pen Streaming Audio Player, Step 3: Done! by Eric Portis (@eeeps) on CodePen.
🎉 Done!
Last updated