ios - Apple Music API,“电台”资源类型播放
问题描述
我正在尝试播放 Apple Music Catalogue 中的“电台”资源。
我通过 Apple Music API 检索广播电台,即搜索目录资源
这给了我一个电台响应(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;
}
通常,对于其他类型的目录资源(播放列表、专辑、歌曲),我采用 'id' 值并将其设置在 ```MPMusicPlayerController` 的播放队列中并开始播放,即:
- (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' 是系统音乐播放器MPMusicPlayerController的一个实例
仅当“id”属于广播电台时,我才会收到此错误。
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}}}
播放电台有不同的机制吗?例如,也许使用 AVPlayer 流式传输电台?
我注意到站响应中的“playParams”包含其他资源类型不包含的两个属性:“格式”和“站哈希”。
我似乎在 Apple 的文档中找不到有关流媒体广播电台的任何内容。
解决方案
推荐阅读
- html - 嵌套 div 的 z-index
- c++ - 形成算法时的未知类型名“vector”和“std”
- django - 如何打印出链接到 django 中特定模型的 ForeignKey 模型?
- javascript - 在本地机器上运行 codepen 项目的问题
- sql - 根据另一张表将一条记录拆分为多条
- php - Json 编码格式错误
- python - Python - 处理数组中项目的最快方法,每个项目都有保证的延迟
- arrays - 如何使用 VBScript 将数组与数组进行比较?
- javascript - Vue 异步组件回调
- c++ - 如何在 C++ 中创建指向向量的静态指针?