Ios 无声模式下的电影音频播放?
很抱歉我的问题,但我已经实现了一个介绍视频,尽管我的iPad有硬件静音开关,但音频仍在播放。 我还在我的应用程序中使用AVAudioplayer,只是为了播放简短的声音样本。在这个类中,它是我设置“AVAudioSessionCategory”的唯一区域。 但是对于所有的音频播放,没有什么可以听到的。这只是我的介绍视频 如何修复“音频错误”使电影播放器静音,有什么帮助吗? 谢谢 这是我的音频课程:Ios 无声模式下的电影音频播放?,ios,mpmovieplayercontroller,avaudioplayer,avaudiosession,Ios,Mpmovieplayercontroller,Avaudioplayer,Avaudiosession,很抱歉我的问题,但我已经实现了一个介绍视频,尽管我的iPad有硬件静音开关,但音频仍在播放。 我还在我的应用程序中使用AVAudioplayer,只是为了播放简短的声音样本。在这个类中,它是我设置“AVAudioSessionCategory”的唯一区域。 但是对于所有的音频播放,没有什么可以听到的。这只是我的介绍视频 如何修复“音频错误”使电影播放器静音,有什么帮助吗? 谢谢 这是我的音频课程: - (id)initWithSoundfileName:(NSString*) file {
- (id)initWithSoundfileName:(NSString*) file
{
if ((self = [super init]))
{
NSString* filename = [file stringByDeletingPathExtension];
NSString* fileextension = [file pathExtension];
// get file path from bundle
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource: filename ofType: fileextension];
NSLog(@"AudioPlayer init: %@", soundFilePath);
NSURL* fileurl = [[NSURL alloc] initFileURLWithPath:soundFilePath];
NSError* error = nil;
AVAudioPlayer* audioplayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileurl error:&error ];
if (error) { NSLog(@"Error creating AVAudioPlayer %@", [error description]);}
// set audio policy
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:NULL];
self.player = audioplayer;
[self.player prepareToPlay];
[self.player setDelegate:self];
}
return self;
}
-(void) play{
[self.player play];
}
下面是我的视频播放方法:
- (void)playIntroVideo
{
NSString *movpath = [[NSBundle mainBundle] pathForResource:@"mymovie" ofType:@"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:movpath];
self.moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
self.moviePlayerController.fullscreen = YES;
self.moviePlayerController.scalingMode = MPMovieScalingModeAspectFit;
self.moviePlayerController.controlStyle = MPMovieControlStyleNone;
self.moviePlayerController.movieSourceType = MPMovieSourceTypeFile;
self.moviePlayerController.useApplicationAudioSession = NO;
[self.moviePlayerController.view setFrame: self.view.bounds];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.moviePlayerController];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlaybackStateChanged:)
name:MPMoviePlayerPlaybackStateDidChangeNotification
object:self.moviePlayerController];
[self.view addSubview:self.moviePlayerController.view];
[self.moviePlayerController prepareToPlay];
[self.moviePlayerController play];
}
比如提到@Till:
当我将
MoviePlayerController
属性更改为useApplicationAudioSession=TRUE
时,它解决了我的问题。音频播放是无声的。为什么要将useApplicationAudioSession
设置为NO
?因为我遇到了类似这样的问题:。但当我将此属性设置为“true”时,音频播放是正确的!!谢谢我将看看上面描述的问题。谢谢你,我很高兴能为你指出正确的方向。