IPhone Sdk Listening to Background Sound

I have an application that plays background music using AVAudioPlayer. The app also has a YouTube video. When a user clicks on a youtube video, I need the background sound to mute. When they either finished watching the video, I need the sound to resume.

Youtube video is played by embedding the video in a UIWebView. View image here

I tried using delegate methods for AVAudioPlayer -

- (void)audioPlayerEndInterruption:(AVAudioPlayer *)player withFlags:(NSUInteger)flags

- (void)audioPlayerBeginInterruption:(AVAudioPlayer *)player

However, it audioPlayerEndInterruptionnever ends the call.

So, ultimately, I need a way to stop the music when the video starts and resumes after the user has finished the video.

A method that could work, but I'm not sure how to implement it:

-Choose a timer that checks for sound on the device, check if it is an audio player (there will be a YouTube player), and then stop the background sound

If anyone has any suggestions, I would really appreciate it.

+3
source share

Source: https://habr.com/ru/post/1786805/


All Articles