我想创建一个 iphone 应用程序,它可以使用我自己的播放/暂停切换按钮和缓冲屏幕(或缓冲状态,然后我可以制作缓冲屏幕)播放在线广播流。任何建议或任何示例代码?
问问题
88 次
2 回答
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];
于 2013-05-23T07:37:33.857 回答
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);
}
于 2013-05-23T07:42:59.360 回答