我必须在我的ios应用程序中播放mp3音频流。所以我用https://github.com/tumtumtum/StreamingKit这个流光。我的演奏方式是这样的
`
audioPlayer = [[STKAudioPlayer alloc] init];
for (int i=0; i<[mutArrayMP3files count]; i++) {
NSLog(@"COUNT %lu",(unsigned long)[mutArrayMP3files count]);
NSString *str=[NSString stringWithFormat:@"http://cp2.comcities.com:1935/lakhanda/default.stream/%@",[mutArrayMP3files objectAtIndex:i]];
NSLog(@"str %@",str);
[audioPlayer queue:str];
// [mutArrayMP3files removeObjectAtIndex:i];
}
[mutArrayMP3files removeAllObjects];
`
但它不起作用。我不知道为什么会这样。
答案 0 :(得分:1)
首先播放STKAudioPlayer并将队列音频文件发送到STKAudioPlayer ..尝试下面的代码 -
NSString *str=[NSString stringWithFormat:@"http://cp2.comcities.com:1935/lakhanda/default.stream/%@",[mutArrayMP3files objectAtIndex:0]];
NSURL* url1 = [NSURL URLWithString:str];
STKDataSource *dataSource = [STKAudioPlayer dataSourceFromURL:url1];
[audioPlayer playDataSource:dataSource withQueueItemID:[[SampleQueueId alloc] initWithUrl:url1 andCount:0]];
for (int i=0; i<urlArr.count; i++) {
NSString *str=[NSString stringWithFormat:@"http://cp2.comcities.com:1935/lakhanda/default.stream/%@",[mutArrayMP3files objectAtIndex:0]];
NSURL* url = [NSURL URLWithString:str];
STKDataSource* dataSource = [STKAudioPlayer dataSourceFromURL:url];
[audioPlayer queueDataSource:dataSource withQueueItemId:[[SampleQueueId alloc] initWithUrl:url andCount:0]];
}