設置AVAudioSession類工作對我來說:
- 查找Xcode中凸出的AppDelegate.m。
- 導入頭文件:AVFoundation/AVFoundation.h
- 添加以下代碼launchOptions {}
內[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionDuckOthers誤差:無];
我的整個這樣的代碼:
#import "AppDelegate.h"
#import "MainViewController.h"
#import <AVFoundation/AVFoundation.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionDuckOthers error:nil];
self.viewController = [[MainViewController alloc] init];
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
@end
注:withOptions:AVAudioSessionCategoryOptionDuckOthers重要。
你的意思是它停止了其他音樂,就像你在背景中玩的那樣? – mlegg
@mlegg如果我播放音樂,例如在背景中,視頻就會停止...我只想顯示視頻的圖像,因爲我想將視頻作爲後臺登錄應用於我的應用,但每次播放音樂時,視頻停止。 –
編輯你的問題,並在那裏添加你所有的html。 – mlegg