MWey
MWey

Reputation: 11

Detect when UIWebview starts playing audio

In the application that I am working on, I have a audio stream (using avplayer) that may or may not be playing (depending on user input). When the user navigates to another page, I have a UIWebView appear with a webpage offering additional links to audio the user can listen to (I do not have direct access to the website's code). The issue is that if the app is currently streaming and the user starts additional audio from the UIWebView, the audio overlaps.

The way I had envisioned to solve this was to pause the stream if the user begins to play something from the UIWebView, and leave it alone if they don't. Is there a way to get a notification when UIWebView starts playing audio from a website? Or is there an alternative to identify when audio from the UIWebView starts being played?

Upvotes: 1

Views: 1027

Answers (1)

Vidhyanand
Vidhyanand

Reputation: 5369

You can use below delegate method of webview to identify the URL and Other useful information when user played the audio using webview so that you can pause the streaming of audio in previous screen..

 - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
     NSLog(@"@@@@@@@@@@@@@Navigation Type is:%ld",navigationType);
     NSLog(@"url: %@ Scheme:%@ Host:%@", [[request URL] absoluteString], request.URL.scheme ,request.URL.host);

    NSString *urlString =[NSString stringWithFormat:@"%@",request.URL];           
    if (navigationType == UIWebViewNavigationTypeOther) 
    {
       NSLog(@“@@@@@@@Pause the Streaming@@@@@@@@@@“);
    }    
      return YES;
    }

In the above find out upon clicking on audio at webview what is the urlString, navigationType so that you can pause the audio streaming..

Hope it will be useful to you..Once check with it..!

Upvotes: 1

Related Questions