我想创建一个iphone应用程序,可以使用我自己的播放/暂停切换按钮和缓冲屏幕(或缓冲状态,然后我可以创建缓冲屏幕)播放在线广播流。有任何建议或任何示例代码吗?
答案 0 :(得分:1)
您可以像这样使用MPMoviePlayerController:
NSURL *mediaURL = [NSURL URLWithString:@"yourStraminglink"];
MPMoviePlayerController *streamingPlayer = [[MPMoviePlayerController alloc] initWithContentURL:mediaURL];
[streamingPlayer setControlStyle:MPMovieControlStyleFullscreen];
[streamingPlayer setMovieSourceType:MPMovieSourceTypeStreaming];
[self.view addSubview:[streamingPlayer view]];
[streamingPlayer prepareToPlay];
[streamingPlayer play];
以及在后台播放的音频会话:
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
[audioSession setActive:YES error:nil];
答案 1 :(得分:1)
您可以尝试使用此代码。
- (void)startPlaying
{
if (streamer)
{
return;
}
[self stopPlaying];
//radio channal url
streamer = [[AudioStreamer alloc] initWithURL:cgf.streamURL];
//NSLog(@"%@",cgf.streamURL);
// Hard coded URL
//NSURL *url = [NSURL URLWithString:@"http://www.freeproxyserver.ca/index.php?btxmnercdeqt=aHR0cDovLzE5OC41MC4xNTIuNzM6ODAwNC9yaHl0aG0%3D"];
//streamer = [[AudioStreamer alloc] initWithURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playbackStateChanged:) name:ASStatusChangedNotification
object:streamer];
//play radio continuously when screen is locked
UInt32 sessionCategory=kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
AudioSessionSetActive(true);
}