gpt4 book ai didi

ios - iPhone-播放电影后,播放音频效果不佳

转载 作者:行者123 更新时间:2023-12-03 02:25:39 24 4
gpt4 key购买 nike

在我的应用程序中,当应用程序启动时,我正在播放介绍视频。在应用程序的稍后部分,我将在单击按钮时播放一些音频文件。但是音频不能很好地播放。注意到其消声和有时音频不足等问题。

我发现错误在于播放视频。当我不播放介绍视频时,音频播放良好。否则会造成麻烦。

我正在使用以下代码来设置电影播放器​​:

-(void)setupMovie
{
NSString* moviePath;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
moviePath = [[NSBundle mainBundle] pathForResource:@"ipad" ofType:@"3gp"];
}
else
{
moviePath = [[NSBundle mainBundle] pathForResource:@"iphone" ofType:@"3gp"];

}

NSURL* movieURL = [NSURL fileURLWithPath:moviePath];
playerCtrl = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
playerCtrl.view.frame = CGRectMake(0, 0, 1024, 768);
}
else
{
playerCtrl.view.frame = CGRectMake(0, 0, 480, 320);
}


playerCtrl.scalingMode = MPMovieScalingModeFill;
playerCtrl.controlStyle = MPMovieControlStyleNone;
[playerCtrl prepareToPlay];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayerLoadStateChanged:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
}

- (void) moviePlayerLoadStateChanged:(NSNotification*)notification
{
if ([playerCtrl loadState] != MPMovieLoadStateUnknown)
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];



// Play the movie
[self.view addSubview:playerCtrl.view];
[playerCtrl play];

[[NSNotificationCenter defaultCenter] postNotificationName:@"GSPLAYER_STARTED" object:nil];
}
else
{
NSLog(@"Player received unknown error");
[[NSNotificationCenter defaultCenter] postNotificationName:@"GSPLAYER_ERROR" object:nil];
}
}

电影播放完后,我将按以下方式加载下一个 View :
-(void)playerCompleted
{
[pv.view removeFromSuperview];
[pv release];
pv = nil;
[self.window addSubview:navigationController.view];
}

以下代码用于播放音频:
-(void)playAudio:(NSString*)filename
{
self.allowAnimation = NO;
NSString* bundleName = [[NSBundle mainBundle] pathForResource:[filename lowercaseString] ofType:nil];

//NSURL* url = [[NSURL alloc] initFileURLWithPath: bundleName];
NSURL* url = [NSURL fileURLWithPath:bundleName];

if (appSoundPlayer) {
[appSoundPlayer release];
}

appSoundPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error: nil];
//[appSoundPlayer prepareToPlay];
[appSoundPlayer setVolume: 1.0];
[appSoundPlayer setDelegate: self];
[appSoundPlayer play];
}

有人较早遇到过此类问题吗?可能是什么问题,将是解决方案?

最佳答案

您是否尝试过设置audioSession属性。仅在播放音频之前将Audiosession设置为要播放。我没有尝试过此代码,但是我认为 session 存在问题。

appSoundPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error: nil];
//[appSoundPlayer prepareToPlay];
[appSoundPlayer setVolume: 1.0];
[appSoundPlayer setDelegate: self];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
[appSoundPlayer play]

关于ios - iPhone-播放电影后,播放音频效果不佳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5575401/

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