How to detect the playing state of the audio in UI

2020-08-01 01:52发布

I have an UIWebView to load a web link:http://m.y.qq.com in my iOS app. I don't know how to detect the playing state of the audio in UIWebView.

I just need to know whether the audio in UIWebView is playing or not in my iOS app, so that I can do something.

I have searched a lot from Stackoverflow and Google, but I can't find a satisfied answer. Can anyone give me some help?

2条回答
贼婆χ
2楼-- · 2020-08-01 02:36

You can check if audio is playing with isOtherAudioPlaying

So in your UIWebView delegate methods you can use:

BOOL isOtherAudioPlaying = [[AVAudioSession sharedInstance] isOtherAudioPlaying];
查看更多
乱世女痞
3楼-- · 2020-08-01 02:51

AVAudioSession has a sharedInstance property which you can utilize in this instance. The property is a BOOL and can be updated upon multiple threads.

@tnylee's code is perfect.

查看更多
登录 后发表回答