lundi 29 juin 2015

AVPlayer not muting with silent switch state


I have a game which is using AVPlayer to stream remote tracks. This music is background audio in the game, so I need it to respect the silent/mute switch on the device.

Following Apple's documentation, I am doing the following:

NSError *error;
NSError *activationError;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryAmbient error:&error];
[audioSession setActive:YES error:&activationError];

AVPlayerItem *item = [[AVPlayerItem alloc] initWithURL:[NSURL URLWithString:@"http://ift.tt/1qHOCFB"]];
self.player = [[AVPlayer alloc] init];

[self.player replaceCurrentItemWithPlayerItem:item];
[self.player play];

// error = nil, and activationError = nil at this point

I have tried this approach for both remote and local files. The files play and can be heard when the device is silent mode, whereas I'm expecting AVPlayer to mute the playback when the silent switch is on.


Aucun commentaire:

Enregistrer un commentaire