开发者

iPhone - After playing movie, playing audio is not doing well

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. Wh开发者_开发百科en 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?


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]


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜