Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMoviePlayerController refuses to play sound through speaker in iOS4

Tags:

iphone

audio

I'm using a MPMoviePlayerController to play some video, I get image, but as soon as I try to play a sound without the earphones, the volume control disappears with an animation. If I plug the earphones, or some external speakers, the volume control returns with an animation.

The app has been tested with an iPad iOS 3.2 and works fine, also with an iPod touch 2G iOS 3.0 and works fine too, but the problem comes with the iPhone 4, and iOS 4.1.

like image 794
Leg10n Avatar asked Oct 04 '10 16:10

Leg10n


1 Answers

I found out it's because I hadn't set the Session category:

NSError *setCategoryError = nil; 
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &setCategoryError]; 

if (setCategoryError) { //handle error } 

http://developer.apple.com/library/ios/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Cookbook/Cookbook.html#//apple_ref/doc/uid/TP40007875-CH6-SW6

like image 182
Leg10n Avatar answered Nov 09 '22 05:11

Leg10n