在我的应用程序中,当应用程序启动时,我正在播放介绍视频。稍后在应用程序中,我正在点击按钮播放一些音频文件。但音频播放效果不佳。它的消音和一些低音频等问题都被注意到了。
我发现错误是播放视频。当我没有播放介绍视频时,音频播放效果很好。否则它会造成麻烦。
我正在使用以下代码设置电影播放器:
-(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];
}
}
电影结束时,我按如下方式加载下一个视图:
-(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];
}
有人早些时候遇到过这些问题吗?可能是什么问题以及解决方案是什么?
答案 0 :(得分:0)
您是否尝试过设置audioSession属性..在播放音频之前只需设置Audiosession即可播放..我还没试过这段代码,但我认为这是会话的问题..
appSoundPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error: nil];
//[appSoundPlayer prepareToPlay];
[appSoundPlayer setVolume: 1.0];
[appSoundPlayer setDelegate: self];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
[appSoundPlayer play]
答案 1 :(得分:0)
问题在于视频编解码器。 如果我们使用的3GP没有AAC格式,那么Apple框架本身就存在一些问题。我联系了Apple,他们接受了它作为一个错误。