Playlists

The ability to make playlists has been introduced in Amplitude 3.0. You can now scope functionality of Amplitude.js into playlists such as play/pause buttons, meta data, next, prev, etc. To make a playlist you must first define all of your songs as song objects in the songs array. This is like your library. You will then make a playlists object when you init Amplitude.js and you will give a key for the unique identifier for your playlist. This key will then contain an array of song indexes being used by your playlist. These are the index of the song in the songs array. The original songs array index will be used in EVERY reference even in a playlist. Consider it the unique ID of the song.

That sounds like a lot, so let's break it down. We will be making a playlist f or Rock and Roll tracks using the following songs:

	Amplitude.init({
		"songs": [
			{
				"name": "Song Name 1",
				"artist": "Artist Name",
				"album": "Album Name",
				"url": "/song/url.mp3",
				"cover_art_url": "/cover/art/url.jpg",
				"genre": "country"
			},
			{
				"name": "Song Name 2",
				"artist": "Artist Name",
				"album": "Album Name",
				"url": "/song/url.mp3",
				"cover_art_url": "/cover/art/url.jpg",
				"genre": "rock"
			},
			{
				"name": "Song Name 3",
				"artist": "Artist Name",
				"album": "Album Name",
				"url": "/song/url.mp3",
				"cover_art_url": "/cover/art/url.jpg",
				"genre": "rock"
			},
			{
				"name": "Song Name 4",
				"artist": "Artist Name",
				"album": "Album Name",
				"url": "/song/url.mp3",
				"cover_art_url": "/cover/art/url.jpg",
				"genre": "classical"
			},
			{
				"name": "Song Name 5",
				"artist": "Artist Name",
				"album": "Album Name",
				"url": "/song/url.mp3",
				"cover_art_url": "/cover/art/url.jpg",
				"genre": "rock"
			},
			{
				"name": "Song Name 6",
				"artist": "Artist Name",
				"album": "Album Name",
				"url": "/song/url.mp3",
				"cover_art_url": "/cover/art/url.jpg",
				"genre": "indie"
			},
			{
				"name": "Song Name 7",
				"artist": "Artist Name",
				"album": "Album Name",
				"url": "/song/url.mp3",
				"cover_art_url": "/cover/art/url.jpg",
				"genre": "rock"
			}
		]
	});

At the end of your config, you will add a key that states you will have playlists including a playlist keyed as "rock_and_roll". Remember these are JSON keys so use underscores!

	"playlists": {
		"rock_and_roll": []
	}

In the playlist we will be adding all the songs that have the genre rock. These are the indexes of songs that will be added. Your final Amplitude.init() method will look like:

	Amplitude.init({
		"songs": [
			{
				"name": "Song Name 1",
				"artist": "Artist Name",
				"album": "Album Name",
				"url": "/song/url.mp3",
				"cover_art_url": "/cover/art/url.jpg",
				"genre": "country"
			},
			{
				"name": "Song Name 2",
				"artist": "Artist Name",
				"album": "Album Name",
				"url": "/song/url.mp3",
				"cover_art_url": "/cover/art/url.jpg",
				"genre": "rock"
			},
			{
				"name": "Song Name 3",
				"artist": "Artist Name",
				"album": "Album Name",
				"url": "/song/url.mp3",
				"cover_art_url": "/cover/art/url.jpg",
				"genre": "rock"
			},
			{
				"name": "Song Name 4",
				"artist": "Artist Name",
				"album": "Album Name",
				"url": "/song/url.mp3",
				"cover_art_url": "/cover/art/url.jpg",
				"genre": "classical"
			},
			{
				"name": "Song Name 5",
				"artist": "Artist Name",
				"album": "Album Name",
				"url": "/song/url.mp3",
				"cover_art_url": "/cover/art/url.jpg",
				"genre": "rock"
			},
			{
				"name": "Song Name 6",
				"artist": "Artist Name",
				"album": "Album Name",
				"url": "/song/url.mp3",
				"cover_art_url": "/cover/art/url.jpg",
				"genre": "indie"
			},
			{
				"name": "Song Name 7",
				"artist": "Artist Name",
				"album": "Album Name",
				"url": "/song/url.mp3",
				"cover_art_url": "/cover/art/url.jpg",
				"genre": "rock"
			}
		],
		"playlists": {
			"rock_and_roll": [
				1, 2, 4, 6
			]
		}
	});

You now have a playlist with a key "rock_and_roll" that contains 4 songs from your library. As we add more features, you will see how this playlist key will come into play to scope the functions of Amplitude.js by playlist.