-2

独自の再生/一時停止トグル ボタンとバッファリング画面 (またはバッファリング状態で、バッファリング画面を作成できます) でオンライン ラジオ ストリームを再生できる iPhone アプリを作成したいと考えています。提案やサンプルコードはありますか?

4

2 に答える 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 に答える