4

I have a weird problem for you all.

MPMoviePlayerController is playing the video fine, and the audio ONLY plays through headphones.

The real drag is that this only happens on some iPads and iPhones, even the SAME EXACT MODELS running the SAME EXACT SYSTEM!

I've created a simple failing example here:

http://www.porcaro.org/MPMoviePlayerController/TestMovie.zip

I've seen it run fine and fail on iPhone 4S, iPhone 4 and iPad 2.

Here is the most relevant code. Thanks for any insight, I'm going to submit a bug to Apple as well:

(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];


    moviePath = [NSString stringWithFormat:@"%@/intro.m4v", [[NSBundle mainBundle] bundlePath]];
    NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
    theMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

    controlStyle = MPMovieControlStyleEmbedded;
    movieView = [self view];
    movieRect = [[self view] frame];
    controlStyle = MPMovieControlStyleFullscreen;

    theMoviePlayer.controlStyle = controlStyle;
    theMoviePlayer.view.userInteractionEnabled = YES;

    if (1) {
        NSLog(@"Created theMoviePlayer: %@.  Playing: %@", theMoviePlayer, moviePath);
    }

    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                          selector:@selector(checkForEndOfMovie:)
                                          name:MPMoviePlayerPlaybackStateDidChangeNotification
                                          object:theMoviePlayer];

    // this line doesn't fix the problem                                                                                                       
    //[theMoviePlayer prepareToPlay];                                                                                                          
    [[theMoviePlayer view] setFrame:movieRect];
    [movieView addSubview: [theMoviePlayer view]];
    [theMoviePlayer play];
}
Jav_Rock
  • 22,059
  • 20
  • 123
  • 164

2 Answers2

5

This is an old question but maybe it'll help someone. I came across the same issue and found out it was happening when the phone is in silent mode only.

Solution is to set the player's useApplicationAudioSession property to false.

[theMoviePlayer setUseApplicationAudioSession:NO];
Willy
  • 9,681
  • 5
  • 26
  • 25
Bora XBora
  • 51
  • 1
  • 2
0

This problem was happen to me once playing video on iPad 2 using mpMoviePlayer. The video was playing perfectly but audio only comes when earphones connected.

Solution to solve the problem:

[theMoviePlayer setUseApplicationAudioSession:NO];
Estel
  • 2,154
  • 2
  • 18
  • 25
Usman Awan
  • 1,208
  • 2
  • 13
  • 30