Overview
Current Version: 5.7.0
(GitHub)
Our iOS SDK is written in Objective-C and works on recent versions of iOS and tvOS. The library can be retrieved via CocoaPods (pod FeedMedia
in your Podfile) or via Swift Package Manager From Xcode 12 onwards you can use Swift Package Manager to add Feed Media to your project.
- Select File > Swift Packages > Add Package Dependency. Enter https://github.com/feedfm/iOS-SDK in the "Choose Package Repository" dialog.
- In the next page, specify the version resolving rule as "Up to Next Major" with "5.7.0" as its earliest version.
- After Xcode checking out the source and resolving the version, you can choose the "FeedMedia" library and add it to your app target.
The iOS SDK contains MarqueeLabel library for a marquee effect on long UILabels that show metadata.
The iOS SDK is kept up to date with all our latest features and handles integration with the iOS lock screen for background playback, if desired.
Getting started
The SDK centers around a singleton instance of this FMAudioPlayer
class, which has simple methods to control music playback (play, pause, skip). The FMAudioPlayer holds a list of FMStation objects (stationList), one of which is always considered the active station (activeStation). Once music playback has begun, there is a current song (currentSong).
Typical initialization and setup is as follows:
As early as you can in your app’s lifecycle (preferably in your AppDelegate or initial ViewController) call
[FMAudioPlayer setclientToken:@"demo" secret:@"demo"]
to asynchronously contact the feed.fm servers, validate that the client is in a location that can legally play music, and then retrieve a list of available music stations.
There are a number of sample credentials you can use to assist in testing your app out. Use one of the following strings for your token and secret to get the desired behavior:
‘demo, demo’
- 3 simple stations with no skip limits
‘badgeo, badgeo
- feed.fm will treat this client as if it were accessing from outside the US
‘counting, counting
- a station that just plays really short audio clips of a voice saying the numbers 0 through 9
To receive notice that music is available or not available, use the whenAvailable:notAvailable:
method call, which is guaranteed to call only one of its arguments as soon as music is deemed available or not:
FMAudioPlayer *player = [FMAudioPlayer sharedPlayer];
[player whenAvailable:^{
NSLog(@"music is available!");
// .. do something, now that you know music is available
// set player settings
player.crossfadeInEnabled = true;
player.secondsOfCrossfade = 4;
[player play];
} notAvailable: ^{
NSLog(@"music is not available!");
// .. do something, like leave music button hidden
}];
// Set Notifications for ex to listen for player events
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stateDidChange:) name:FMAudioPlayerPlaybackStateDidChangeNotification object:[FMAudioPlayer sharedPlayer]];
Audio Session notes
The SDK is configured, by default, to create an AVAudioSession
with the category AVAudioSessionCategoryPlayback
, the mode
AVAudioSessionModeDefault
, and the category option AVAudioSessionCategoryOptionMixWithOthers
. This allows the SDK to play audio
in the background and mix with other audio sources. If you are only playing Feed.fm music in your app, and you want the music to appear
in and be controlled via the lock screen, then the category option must be set to 0
. This can be done by calling
setAVAudioSessionCategory:mode:options:
.
UI Elements
The iOS SDK contains UI elements like play/pause, skip and like/dislike buttons that can be used directly but setting the class. You can find a full list of all the classes in the Feed.fm iOS SDK reference docs. The source code for UI elements is public on our github repo as well.
iOS Demo Apps
We have 3 fully functional music player interfaces available as XCode projects on GitHub.
- RadioPlayer: implements a simple tab interface to let the user switch between and control 2-3 streaming radio stations.
- RadioPlayer 2: supports any number of stations (by offering a page to list all available stations) and all our different station types (streaming, on-demand, simulcast and offline).
- Swift Demo