Forum Xamarin.iOS

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

WKWebView with HTML5 animation

RicheyMBRicheyMB Member ✭✭

I have a WKWebView in my project which is playing an HTML5 animation. I also need to playback speech. When the speech is playing the animation freezes until the speech is complete.

I am guessing this is because the animation is playing on the UI thread, is there any way to prevent this?

Tagged:

Best Answer

  • RicheyMBRicheyMB Member ✭✭
    Accepted Answer

    I have found a solution, although I am not certain why it fixes the issue.

    If I set

    AVAudioSession.SharedInstance().SetCategory(AVAudioSessionCategory.Playback, AVAudioSessionCategoryOptions.DuckOthers);
    

    Then the speech continues over the HTML5 audio.

    I don't know why this is the case when the website is local (temp folder) and opened using WkWebView.LoadFileUrl() and not when the website is remote and opened using WKWebView.LoadRequest()

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    How did you play the audios?
    Could you please show some related code here?
    If you don't want the code run on the main thread, try to wrap the snippet like:

    Task.Run(() =>
    {
        // Play audios here
    });
    
  • RicheyMBRicheyMB Member ✭✭

    The audio is text to speech using AVSpeechSynthesizer. I looked to implement Task.Run and it is already in a separate task. So my initial thoughts a potentially wrong.

    If I breakpoint the speech the animation continues playing.

    The HTML is being stored on the device, interestingly if I host it on a server and point to that, rather than the local files, it is fine. Unfortunately that cannot be a solution as the HTML must be encrypted.

  • LandLuLandLu Member, Xamarin Team Xamurai

    Could you please share a sample here to help me reproduce the issue?

  • RicheyMBRicheyMB Member ✭✭
    Accepted Answer

    I have found a solution, although I am not certain why it fixes the issue.

    If I set

    AVAudioSession.SharedInstance().SetCategory(AVAudioSessionCategory.Playback, AVAudioSessionCategoryOptions.DuckOthers);
    

    Then the speech continues over the HTML5 audio.

    I don't know why this is the case when the website is local (temp folder) and opened using WkWebView.LoadFileUrl() and not when the website is remote and opened using WKWebView.LoadRequest()

  • LandLuLandLu Member, Xamarin Team Xamurai

    This option is used to reduce the volume of other audio sessions.
    I've no idea why it works for you as lacking your sample here.
    Fortunately, if this issue has been solved, try to mark it as the answer.

Sign In or Register to comment.