Adding Web-Radio to Your App with Feed.FM

by

Feed Media API We’ve been working with Feed.FM, which allows you to quickly integrate their web-radio hosting service into your Android app! You’ll be able to Play, Pause, Skip songs and switch playlists; we’ve abstracted all the nitty-gritty details for you.

You won’t need to handle any of the Rest API handling; a 30 minutes four step process should be enough to get up, running and playing music. You’ll hit Play, and music will be streamed down and cycled from your playlist.
Music will keep playing while your application is in the background; just start playing and it won’t stop until you pause the track.

Step 1: Register on Feed.FM

Step 2: Set up your first online radio station

  1. 1. Go to your dashboard
  2. 2. Click the Create your App/Website button
  3. 3. Are you adding music to a website or an app? Check app duh
  4. 4. What platform does this app run on? that will be Android
  5. 5. Create
  6. 6. From there, Post Music or just pick an existing FUZZ station!

Step 3: Gradle dependency

Add this to your build.gradle

[code lang=”javascript”]
dependencies {
// …
compile (‘fm.feed.android:player-sdk:1.1.+@aar’) {
transitive = true
}
}
[/code]

Step 4: Start Playing

[code lang=”java”]
final Player player = Player.getInstance(getContext(), new Player.PlayerListener() {
@Override
public void onPlayerInitialized(PlayInfo playInfo) {
player.play();
}

@Override
public void onPlaybackStateChanged(PlayInfo.State state) {
// Called when the playback changes state
}

@Override
public void onError(PlayerError playerError) {
// Called when there is an error
}

@Override
public void onNotificationWillShow(int notificationId) {
// Called when the Foreground Service notification is created
}
}, AUTH_TOKEN, AUTH_SECRET, CUSTOM_NOTIFICATION_ID);
[/code]

Getting your AUTH_TOKEN and AUTH_SECRET:

  1. 1. On your developer dashboard click on your listed app
  2. 2. Switch to the tab Developer Codes and IDs
  3. 3. Copy & Paste the token and secret into your Android application

Note on the Notification:
The Player will keep playing music even when your app is in the background.
Android allows this by requiring that we display a notification to the user, letting him know that your application is still running. The CUSTOM_NOTIFICATION_ID will be the notification identifier used for sharing the Notification object between the app and the Feed.FM Player service.
The user should be able to click on the notification to get back to the app; but you can also give more functionality to the user there: he could Play, Pause or Skip songs without having to go into the app.
To stop the player from running in the background, just

[code lang=”java”]player.pause();[/code]

the music before exiting the application.

Extras:

Here’s a short list of things you can do with the Player SDK:

[code lang=”java”]
player.tune() // pre-download a song
player.play()
player.pause()
player.skip()
player.like()
player.registerNavListener(Player.NavListener) // listen to navigation events
player.setStationId(stationId) // change station
[/code]

The code is open source and is available on GitHub @ http://github.com/fuzz-radio/Android-SDK

Leave a Reply

Your email address will not be published. Required fields are marked