在我的HTML代码中,如果我同时播放音乐,视频就会停止。我的代码如下:
<video autoplay id="video-bg" webkit-playsinline loop>
<source src="videos/login_bg2.mp4" type="video/mp4">
<source src="videos/login_bg2.webm" type="video/webm">
</video>
我该如何解决这个问题?
提前致谢
答案 0 :(得分:0)
设置AVAudioSession类别适用于我:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionDuckOthers error:nil];
我的整个代码都是这样的:
#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
&#13;
注意: withOptions:AVAudioSessionCategoryOptionDuckOthers 很重要。