0

次のコードは、find だけでオーディオをストリーミングするコードです。

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:stringURL]];
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    connectionPlay = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    NSError *playerError;
    player = [[AVAudioPlayer alloc] initWithData:streamData error:&playerError];
    player.numberOfLoops = 0;
    player.volume = 1.0f;
    [player prepareToPlay];

    if (playerError) {
        NSLog(@"audio player error: %@", [playerError localizedDescription]);
    }
    if (player == nil)
        NSLog(@"%@", [playerError description]);
    else
        [player play];

アプリをバックグラウンド モードにしようとすると、再生が停止します。.plist に入り、必要なバックグラウンド モード、アイテム 0、アプリがオーディオを再生します。これで問題は解決しませんでした。

私はこれを置き始めました:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
                                       error:nil];
[[AVAudioSession sharedInstance] setActive:YES
                                     error:nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

の中に

- (void)applicationWillResignActive:(UIApplication *)application

- (void)applicationDidEnterBackground:(UIApplication *)application

メインViewControllerのviewDidLoad内。[player prepareToPlay] の直後も同様です。

問題が適切なバックグラウンド設定を設定していないのか、アプリが接続を切断しているのかはわかりません. 基本的に、何が欠けているのかわかりません。

私は見てきました:

http://developer.apple.com/library/ios/#documentation/AVFoundation/Reference/AVAudioSession_ClassReference/Reference/Reference.html

https://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/はじめに/はじめに.html

編集:誰か?

4

1 に答える 1

1

それが何だったのかわかりませんが、すべてのコードを新しいプロジェクトに転送し、このコードを追加しました

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

    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
                                           error:nil];
    [[AVAudioSession sharedInstance] setActive:YES
                                         error:nil];
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

およびplistの設定で、電話では機能するようですが、シミュレーターでは機能しません..

于 2013-01-08T19:34:49.417 に答える