简体   繁体   中英

How to mute a audio sound when an action is tapped?

Adcolony is a video advert platform integrated into Xcode to play ads to users in video and sound,

One of the requirements is to block audio when the add starts playing,

This is the audio:

 //Audio Sound On - uncomment
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                  pathForResource:@"soundTrack"
                                  ofType:@"mp3"]];
audioPlayer = [[AVAudioPlayer alloc]
                           initWithContentsOfURL:url
                          error:nil];

it starts as soon as the game starts, in view controller,

The triggerVideo action is place in PlayViewController and needs to be set off when ad is triggered,

- (IBAction)TriggerVideo:(id)sender {
[AdColony playVideoAdForZone:@"ZONE-NUMBER-HERE" withDelegate:nil];
}

I've left this aside for a while now, wondering if anyone knows how to employ this function?

add these methods to your viewController that's the delegate for adcolony, which should also be the viewcontroller in which you initialize the AVAudioPlayer. I probably don't need to state this, but i'm assuming you have an @Property for your audioPlayer

- (void) onAdColonyAdStartedInZone:(NSString *)zoneID{
  self.audioPlayer.volume = 0.0f;
}

- (void) onAdColonyAdAttemptFinished:(BOOL)shown inZone:(NSString *)zoneID{
  self.audioPlayer.volume = 1.0f;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM