Domanda

I am playing videos and audio in my iOS app using AVAudioPlayer for Audio files (.mp3 files) and MPMoviePlayerViewController for videos files (.mp4 files).

It works fine on iOS 5 and lower versions.

But in my iPad ( iOS 6) it doesn't work. It plays video with no audio. Of course it doesn't play audio at all.

Please help me to resolve this problem. Thanks in advance ...

È stato utile?

Soluzione

Since iOS 6 the mute switch will also mute apps, did you check if the mute swoth is turned off.

To force playback if the device is muted you could do the following:

NSError *error= nil;
if ([[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:&error]) {
    NSLog(@"Error setting audio session: %@", error);
}

Altri suggerimenti

NSError *setCategoryErr = nil;
NSError *activationErr  = nil;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&setCategoryErr];
[[AVAudioSession sharedInstance] setActive:YES error:&activationErr];

if(setCategoryErr || activationErr)
{
    NSLog(@"%@ Error: Could not activate silence mode. %@ %@", self, setCategoryErr, activationErr);
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top