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

发布于 2024-10-30 17:58:34 字数 3329 浏览 1 评论 0原文

在我的应用程序中,当应用程序启动时,我正在播放介绍视频。稍后在应用程序中,我通过单击按钮播放一些音频文件。但音频播放效果不佳。注意到它的消音和有时低音频等问题。

我发现这个错误是在播放视频时出现的。当我不播放介绍视频时,音频播放得很好。否则就会造成麻烦。

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

-(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];  
}

有人之前遇到过此类问题吗?可能存在什么问题以及解决方案是什么?

In my application, when the app starts, I'm playing an introduction video. Later in the application, I'm playing some audio files on click of buttons. But the audio is not playing well. Its muffling and some times low audio etc problem are noticed.

I found the bug is with playing video. When I'm not playing the introduction video, the audio is playing well. else it is causing trouble.

I'm using the following code to set up movie player:

-(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];
    }
}

When movie finishes, I'm loading next view as follows:

-(void)playerCompleted
{
    [pv.view removeFromSuperview];
    [pv release];
    pv = nil;
    [self.window addSubview:navigationController.view];
}

The following code is to play audio:

-(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];  
}

Has someone came across such issues earlier? What might be the problem and what will be the solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜光 2024-11-06 17:58:34

您是否尝试过设置audioSession属性..只需设置 Audiosesion 在播放音频之前播放..我还没有尝试过这段代码,但我认为这是会话的问题..

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

Have you tried to set audioSession properties..Just set Audiosession to playback before playing audio..I havent tried this code, but I think it is a problem with sessions..

appSoundPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error: nil];
//[appSoundPlayer prepareToPlay];
[appSoundPlayer setVolume: 1.0];
[appSoundPlayer setDelegate: self];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
[appSoundPlayer play]
零時差 2024-11-06 17:58:34

问题出在视频编解码器上。
如果我们使用没有 AAC 格式的 3GP,则 Apple 框架本身存在一些问题。我联系了苹果公司,他们接受了这是一个错误。

The problem is with the video codec.
If we are using 3GP not having AAC format, there's some issue with Apple framework itself. I contacted Apple and they accepted it as a bug.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文