加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – SoundCloud API iOS,无共享 – 只收听

发布时间:2020-12-14 17:28:51 所属栏目:百科 来源:网络整理
导读:我有一个网站,我用SoundCloud制作播放列表.现在我想为iPhone制作一个应用程序,这样用户也可以收听那里的歌曲. http://developers.soundcloud.com/docs/api/ios-quickstart 在链接的示例中,用户必须登录才能收听和分享,但我希望我的用户只能收听.有没有办法让
我有一个网站,我用SoundCloud制作播放列表.现在我想为iPhone制作一个应用程序,这样用户也可以收听那里的歌曲.

http://developers.soundcloud.com/docs/api/ios-quickstart
在链接的示例中,用户必须登录才能收听和分享,但我希望我的用户只能收听.有没有办法让他们不必登录?

解决方法

创建一个以JSON格式输出播放列表的页面,然后在xcode中创建一个类,用于下载轨道词典的JSON并使用AVPlayer播放下载的内容(如果您正在播放整个列表,则播放AVQueuePlayer).

这是一些抽象代码:

playlistDownloader.m
- (void)downloadPlaylist{
dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0);

dispatch_sync(concurrentQueue,^{
    NSURL *url = [NSURL URLWithString:@"http://www.yourwebsite.com/playlist.json?id=1"];
    NSData *data = [NSData dataWithContentsOfURL:url];
    NSError *error;

    id trackData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];

    if (!error) {
        tempTrackArray = trackData;
    } else {
        NSLog(@"Playlist wasn't able to download");
    }
});
}

tempTrackArray将是类中声明的属性.

然后在你的播放器中,你会做这样的事情:

audioPlayer.m
- (void)instanciateAudioPlayer
{
NSDictionary *trackDictionary = [playListDownloader.tempTrackArray objectAtIndex:0];
NSString *urlString = [trackDictionary objectForKey:@"stream_url"];

AVAsset *asset = [AVAsset assetWithURL:streamURL];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];

[avPlayer initWithPlayerItem:playerItem];
}

这是一些非常粗略的代码,但它是你想要做的一般要点.应该让你朝着正确的方向前进.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读