2

iPhoneアプリがバックグラウンドでラジオを再生またはストリーミングできるかどうかを確認する必要があります。

正常に動作するラジオアプリを作成しました。

ユーザーがバックグラウンドプロセスでラジオを再生できる機能を追加したいと思います。つまり、ラジオを再生するためにアプリケーションを開いたままにする必要はありません。

彼らはアプリを閉じることができ、ラジオはまだ再生されています。

Appleにはアプリがバックグラウンドでラジオを実行できるプライベートAPIがあることを昔から読みましたが、プライベートなので使用できません。

助言がありますか?

4

3 に答える 3

4

iOSSDKは4.0より上である必要があります。デリゲートコードの最初:

- (void)applicationDidEnterBackground:(UIApplication *)application {

    if (isAbove4_0)

 {

        CTCallCenter *_center = [[CTCallCenter alloc] init];

        _center.callEventHandler = ^(CTCall *call) 
       {

            //NSLog(@"call:%@", call.callState);
            if ([call.callState isEqualToString:CTCallStateIncoming]) 

                {

                [RadioPlayer pausePlayer];

        }           
    };
    }

}

次に、MPMoviePlayerControllerを使用しましたが、AVPlayerは問題ありません。

if (isAbove4_0) {
    if (_mpmovieplayer == nil) {
        _mpmovieplayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
        [_mpmovieplayer setMovieControlMode:MPMovieControlModeHidden];
    }

    [_mpmovieplayer setContentURL:url];
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
    [[AVAudioSession sharedInstance] setActive: YES error: nil];
    // This is necessary if you want to play a sequence of songs, otherwise your app will be
    // killed after the first one finishes.
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

    UIBackgroundTaskIdentifier newTaskId = UIBackgroundTaskInvalid;

    [_mpmovieplayer play];

    newTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
    if (newTaskId != UIBackgroundTaskInvalid && bgTaskId != UIBackgroundTaskInvalid)
        [[UIApplication sharedApplication] endBackgroundTask: bgTaskId];
    bgTaskId = newTaskId;

}

PS:私の英語は下手です、これがあなたに役立つことを願っています:)

于 2011-03-29T03:50:01.920 に答える
3

これらのオーディオストリーマーの1つを使用して、バックグラウンドで再生できます

https://github.com/mattgallagher/AudioStreamer

https://github.com/DigitalDJ/AudioStreamer

それはあなたを助けるかもしれません。

于 2011-03-29T04:09:32.250 に答える
0

これは私にとってそれがどのように機能するかです。

以下をapp-info.plistファイルに追加します

<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>

次に、application:didFinishLaunchingWithOptionsで以下を追加します

UIBackgroundTaskIdentifier backgroundTask = [application beginBackgroundTaskWithExpirationHandler:^{
     /* just fail if this happens. */
     NSLog(@"BackgroundTask Expiration Handler is called");
     [application endBackgroundTask:backgroundTask];
}];
于 2013-02-19T13:11:24.847 に答える