1

我正在我的应用程序的 MPMoviePlayer 中播放视频,我正在从服务器获取视频。如果视频长度约为 25 秒或更长,则音频会中断。意味着在播放视频时,当视频播放到一半时,就听不到音频了。但是如果我寻找进度条,音频又来了。

任何人都可以帮助我吗?

moviePlayerController = [[MPMoviePlayerController alloc] init];
[moviePlayerController prepareToPlay];
moviePlayerController.shouldAutoplay = YES;
[moviePlayerController setScalingMode:MPMovieScalingModeAspectFit];
[[self.moviePlayerController view] setFrame:CGRectMake(0, 72, 320,180)];
[[self view] addSubview: [self.moviePlayerController view]];
self.moviePlayerController.useApplicationAudioSession = YES;

 NSString *strng = @"http://qdemo_videos.s3.amazonaws.com/1360582540.mp4";
 NSURL * adurl = [NSURL URLWithString:strng];
 moviePlayerController.contentURL = url;
 moviePlayerController.controlStyle = YES;
 self.moviePlayerController.useApplicationAudioSession = YES;
  [moviePlayerController play];
4

1 回答 1

-1

如果你是在 Xcode 4.6 或更高版本上构建并使用 iOS 6.0 或更高版本,

self.moviePlayerController.useApplicationAudioSession = YES;

不会被称为已弃用。

如需进一步使用此链接:这是文档 http://developer.apple.com/library/ios/#documentation/AVFoundation/Reference/AVAudioSession_ClassReference/Reference/Reference.html

这是解释http://developer.apple.com/library/ios/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Configuration/Configuration.html

如果这还不够,这里是代码:) http://developer.apple.com/library/ios/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Cookbook/Cookbook.html#//apple_ref/doc/uid/TP40007875- CH6-SW2

在我的情况下,将类别设置为 AVAudioSessionCategoryAmbient 就可以了!

于 2013-02-25T13:04:44.087 回答