在我的應用程序中,當應用程序啓動時,我正在播放介紹視頻。後來在應用程序中,我點擊按鈕播放一些音頻文件。但音頻播放不好。它的消聲和有時低音頻等問題被注意到。iPhone - 播放電影后,播放音頻效果不佳
我發現錯誤是播放視頻。當我不播放介紹視頻時,音頻播放效果很好。否則會造成麻煩。
我用下面的代碼來設置電影播放:
-(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];
}
有人遇到過這樣的問題嗎?什麼可能是問題,解決方案是什麼?
這是否發生在模擬器和設備上?如果它在模擬器上沒有發生,我會在設備上的耳機上測試音頻。我已經有奇怪的階段取消問題播放立體聲文件,混合到單聲道的單個揚聲器... – diatrevolo 2011-04-07 02:56:17
我測試它只在設備上,而不是在模擬器。我正在使用非常好的頭戴式耳機,並注意到音頻問題。你是如何解決這個問題的? – Satyam 2011-04-07 02:58:06
嗯,不......我指的問題不會在耳機上出現,只能在揚聲器上出現。 – diatrevolo 2011-04-07 03:14:38