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 ...

有帮助吗?

解决方案

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);
}

其他提示

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);
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top