4

Ever since I updated to iOS 5, I can't get MPMoviePlayerViewController to play audio on the iPad. Video is perfect, but no audio is heard. It doesn't matter what format I use. It does not work. It works in the simulator, but not on the iPad.

- (IBAction)playVideo {

    NSString *filepath   =   [[NSBundle mainBundle] pathForResource:@"test" ofType:@"m4v"];
    NSURL    *fileURL    =   [NSURL fileURLWithPath:filepath];
    moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];

    [[NSNotificationCenter defaultCenter]
     addObserver:self selector:@selector(movieFinishedPlaying:)
     name:MPMoviePlayerPlaybackDidFinishNotification 
     object:[moviePlayer moviePlayer]];

    [self presentMoviePlayerViewControllerAnimated:moviePlayer];

}

Anyone else have this problem? Or found a fix?

RyeMAC3
  • 1,023
  • 1
  • 10
  • 17

5 Answers5

11

It sounds silly, but we came across an issue on my team where the volume control for general iPad sounds was muted and this meant that there was no sound for video played in our app, even though music played through the music player or video on websites worked fine.

To check this volume control you can bring up the task manager (double-tap the home button) and then swipe across to the far left and there are some music controls; check that the mute button on this screen is not on.

Zoodor
  • 424
  • 2
  • 4
  • 15
4

set audio session before allocating MPMoviePlayerController will play sound along with video

AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayback error:nil];
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
Anshul
  • 420
  • 1
  • 9
  • 16
4

try this:

...
moviePlayer.useApplicationAudioSession = NO;
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
Fish
  • 173
  • 1
  • 6
1

I just made the slide button on the side into lock screen. Then the sound suddely worked.

1

Ensure the audio format in the video file is something that the iPad can play. I believe the simulator has access to the host machine's codecs, which might explain why the iPad can play the video but not the audio. As noted on this page in the MPMoviePlayerController documentation:

If you use this class to play audio files, it displays a white screen with a QuickTime logo while the audio plays. For audio files, this class supports AAC-LC audio at up to 48 kHz, and MP3 (MPEG-1 Audio Layer 3) up to 48 kHz, stereo audio.

  • I tried several formats. Even just a plain mp3. All these files used to play on iOS 4 without a problem. They all play in the iPad music/video apps fine. They just do not have audio when played in my app. It's not the file, it's the OS. Something in iOS 5 has changed. – RyeMAC3 Jan 14 '12 at 23:16
  • 1
    Gotta be kidding me!! The iPad mute control to the left of the multitasking bar was enabled. (Not the switch) Even though audio plays in every other app and vol is up, that mute control disables audio in my app. Gotta be a bug. – RyeMAC3 Feb 08 '12 at 01:25