gpt4 book ai didi

ios - 尽管在静音模式下电影的音频播放?

转载 作者:行者123 更新时间:2023-11-28 22:52:45 25 4
gpt4 key购买 nike

很抱歉我的问题,但我实现了一个介绍视频,尽管我的 iPad 有硬件静音开关,但音频仍在播放。我也在我的应用程序中使用 AVAudioplayer 来播放简短的声音样本。在这个类中,它是我设置“AVAudioSessionCategory”的唯一区域。但仅对于所有音频播放,听不到任何声音。它仅用于我的介绍视频。

对于如何修复“音频错误”以使电影播放器​​保持静音,有什么帮助吗?谢谢你

这是我的音频类:

- (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 时,它解决了我的问题。音频播放静音。

关于ios - 尽管在静音模式下电影的音频播放?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11528986/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com