AirPlay Native
Solution 2: Integrating Feed.fm iOS SDK with native Airplay
As an alternative solution we support native Airplay through muxing. The current Feed.fm iOS SDK plays audio independently of any video content played by client apps. Therefore, it is not immediately compatible with Apple AirPlay, as AirPlay is only designed to send a single audio–video stream to the TV. As a result, in order to support AirPlay we have an AirplayMuxer
SDK that works in conjunction with the iOS SDK to mix the client video and our music into a single file that is compatible with AirPlay.
AirplayMuxer
extracts the video and audio tracks from the video stream, re-transcodes the audio with Feed music overlayed onto it, and then muxes the result back into a single video stream. Since this is done on-the-fly, the SDK starts streaming as soon as the first part of the video is ready, and replaces the older video with a new video that contains the combined content.
If you intend to use this solution, please contact your Account Executive or Success Manager for access to the GitHub example repository, as it is currently private.
Integration
To get started with AirplayMuxer
get the SDK from CocoaPods and add it to your Podfile:
pod 'AirplayMuxer'
Run pod install
and import the framework by
#import <AirplayMuxer/AirplayManager.h>
Initializing the SDK
- Initialize FeedSDK as you would without AirPlay.
- Create a new AirplayManager instance, and call
registerAirplayDelegate
with the Feed.fm station and settings. - Implement the
AirplayDelegate
to get notifications when the AirPlay starts and stops. TheAirplayManager
will automatically take over playback when AirPlay starts. - Once the video is finished playing, the
AirplayManager
instance should be discarded. A new instance should be created for every video that starts playback.
Sample
[player whenAvailable:^{
NSLog(@"Feed Music Available");
self->_airPlayer = [[AirplayManager alloc] init];
[self->_airPlayer registerAirplayDelegate:self withOriginalUrl:videoURL musicVolume:0.15 withStation:player.stationList[1] withCrossfade:4];
[player play];
} notAvailable:^{
NSLog(@"Not available");
}];
AirplayDelegate
requires implementing three methods:
(CMTime)onAirplayStarted:(AVPlayer *)avplayer
(void)onAirplayStopped:(CMTime)time
(void) onDeviceInfo:(NSString*) airplayDevice;
In onAirplayStarted
the user should pause all media including Feed. In onAirplayStopped
, both feed and video should be restarted. The time returned is the last timestamp of the video after AirPlay was stopped.
OnDeviceInfo
is called to expose the user-agent string of the AirPlay device for logging and reporting purposes.
Once a video is completed, it can’t be replayed again. To restart the video you need to call registerAirplayDelegate
again so new music can be retrieved.
Make sure registerAirplayDelegate
is only called one time with a First Play station as the station will run out of music once AirPlay starts on the TV.
AirPlay Quirks: Connections to Apple TV, Roku, Samsung TVs, and LG TVs are all tested and working at the time of this writing, but these types of connections should be manually retested with each beta release of AirPlay, as Apple is known to break backward compatibility.
HLS Live Playlists, which remove older sections, are currently not supported.