0
NSError *sessionError = nil;
[[AVAudioSession sharedInstance] setDelegate:self];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&sessionError];
[[AVAudioSession sharedInstance] setActive:YES error:nil];

//Direct audio to speakers when there is no headphone
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];


[player setAllowsExternalPlayback:YES];
[player setUsesExternalPlaybackWhileExternalScreenIsActive: YES];
[player setAllowsAirPlayVideo:NO];

上記は、適切なセッションを設定して Airplay を有効にしようとする私のコードです。動作する場合もありますが、動作するかどうかに関係なく、通常は添付画像をご覧くださいAirplay メニューに「iPhone」が 2 回表示され、実際の Airplay デバイスが表示されないことがあります。これら 2 つの重複するオプションのいずれかをタップしても、何も起こらないようです。また、ステータスバーの再生アイコンが表示される場合と表示されない場合があります。セッションが毎回適切に設定されていないと推測しています。

ここで私が間違っていることを誰か親切に教えてもらえますか?! また、Bluetooth での再生を有効にしたい場合、他のデリゲートを実装する必要がありますか?

4

2 に答える 2

1

このモードであなたのコードを使用して、今日あなたの投稿を見ます:

あなたの AppDelegate .M でこれ:

NSError *sessionError = nil;
[[AVAudioSession sharedInstance] setDelegate:self];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:&sessionError];
[[AVAudioSession sharedInstance] setActive:NO error:nil];

UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);

UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

そして、これを使用してView.mで:

[player setAllowsExternalPlayback:YES];
[player setUsesExternalPlaybackWhileExternalScreenIsActive: YES];
[player setAllowsAirPlayVideo:NO];//this is deprecated in iOS 6.0

これがあなたや将来の人々に役立つことを願っています!

于 2013-04-10T09:58:00.810 に答える
0

わかりましたが、同時に単純で奇妙です:)機能を削除するだけです。

この方法:

[player setAllowsExternalPlayback:YES];
[player setUsesExternalPlaybackWhileExternalScreenIsActive: YES];
[player setAllowsAirPlayVideo:NO];//this is deprecated in iOS 6.0

になる:

[player setAllowsExternalPlayback:YES];
[player setUsesExternalPlaybackWhileExternalScreenIsActive: YES];

info.plistRequired Background Modesを許可し、設定: App Plays AudioおよびApp Communicates with an accessoriesを設定し、1 行追加して設定: Application uses WiFiを設定します。

それだけです;)

PS:ここで私の問題を解決できる可能性があります。

于 2013-04-17T08:09:45.337 に答える