I am trying to play 'stations' resources from Apple Music Catalogue.
I retrieve the radio station via the Apple Music API i.e. Search for Catalogue Resources
which gives me a station response (StationResponse):
{
attributes = {
artwork = {
bgColor = ff9f0e;
height = 1080;
textColor1 = 0f0800;
textColor2 = 190a00;
textColor3 = 3f2603;
textColor4 = 472802;
url = "https://is4-ssl.mzstatic.com/image/thumb/Features111/v4/cd/ea/5a/cdea5a14-9789-26f5-8714-17b1db8f1021/source/{w}x{h}sr.jpeg";
width = 4320;
};
editorialNotes = {
name = "Pure Country";
short = "Today's biggest hits.";
};
isLive = 0;
name = "Pure Country";
playParams = {
format = tracks;
id = "ra.985486583";
kind = radioStation;
stationHash = CgkIBBoF96n11QMQAg;
};
url = "https://music.apple.com/ca/station/pure-country/ra.985486583";
};
href = "/v1/catalog/ca/stations/ra.985486583";
id = "ra.985486583";
type = stations;
}
Normally, for other types of catalogue resources (playlists, albums, songs), I take the 'id' value and set it in the ```MPMusicPlayerController`'s playback queue and playback begins i.e.:
- (void)beginPlaybackForStoreID:(NSString *)storeID
{
__weak typeof(self) weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
if (@available(iOS 9.3, *)) {
__strong typeof(self) strongSelf = weakSelf;
// Store id for 'pure-country' radio station is: ra.985486583
// https://music.apple.com/ca/station/pure-country/ra.985486583
[strongSelf.musicPlayerController setQueueWithStoreIDs:@[storeID]];
[strongSelf.musicPlayerController play];
} else {
// Fallback on earlier versions
NSLog(@"Not able to setQueueWithStoreIDs on this version of iOS");
}
});
}
'musicPlayerController' is an instance of the system music player MPMusicPlayerController
I receive this error only when the 'id' belongs to a radio station.
2020-05-20 10:37:42.681961-0700 ---[61653:10276450] [RemoteControl] userIdentityForMediaRemoteOptions -❗️No user identity data. Using active account.
2020-05-20 10:37:42.774906-0700 ---[61653:10276375] Audio session options array to bitmask: 1
2020-05-20 10:37:43.359056-0700 ---[61653:10276523] [SDKPlayback]
-[MPMusicPlayerController prepareToPlayWithCompletionHandler:] completed id=systemMusicPlayer error:
Error Domain=MPCPlayerRequestErrorDomain Code=1000 "Failed to send command 122"
UserInfo={NSDebugDescription=Failed to send command 122,
NSUnderlyingError=0x281170150 {Error Domain=MPCPlayerRequestErrorDomain Code=1000 "Failed to send command 122 (MRMediaRemoteCommandHandlerStatus = 2)"
UserInfo={NSDebugDescription=Failed to send command 122 (MRMediaRemoteCommandHandlerStatus = 2),
MPCPlayerErrorKeyMediaRemoteCommandHandlerStatus=2}}}
Is there a different mechanism for playing stations? For instance, maybe using AVPlayer to stream the station?
I've noticed that the 'playParams' in a station response contains two properties that other resources types do not contain: 'format' and 'stationHash'.
I can't seem to find anything in Apple's documentation regarding streaming radio stations.