Video from an embedded tweet doesn’t play with WKWebView in some circumstances

I’m faced an issue of playing video from embedded to HTML tweets. The behavior which I’m looking for is simple enough: to have a possibility to tap on the play button to play videos. But my app can have videos from different resources e.g. Twitter, YouTube etc. and I want to play all videos the same way: by tapping on the play button. However, with some WKWebView configurations the twitter video doesn’t play but other videos play correctly and with another WKWebView configurations the twitter video plays correctly but in the same time other videos can play automatically, which is not correct behavior.

Here is my code example of WKWebView configuration and HTML loading:

let configuration = WKWebViewConfiguration()
        configuration.allowsInlineMediaPlayback = true
        // Twitter video doesn't play, other videos can play by tap action
        configuration.mediaTypesRequiringUserActionForPlayback = .all
        
        // Twitter video doesn't play, other videos can play by tap action
//        configuration.mediaTypesRequiringUserActionForPlayback = .video
        
        // Twitter video plays correctly by tap action, but other videos can play automatically which is not correct behaviour for me
//        configuration.mediaTypesRequiringUserActionForPlayback = .audio
        
        // Twitter video plays correctly by tap action, but other videos can play automatically which is not correct behaviour for me
//        configuration.mediaTypesRequiringUserActionForPlayback = []
        
        let html = """
        <html>
           <body>
              <blockquote class="twitter-tweet">
                 <p lang="en" dir="ltr">Jamie Carragher meets James Bond 🤝<br><br>Daniel Craig discusses his love of Liverpool, the thrill he felt meeting the players in person, his final appearance as James Bond, and whether Jurgen Klopp would make a good 007 🎬⚽<a href="<some_link>">pic.twitter.com/kxYrAO3LIh</a></p>
                 &mdash; Sky Sports News (@SkySportsNews) <a href="https://twitter.com/SkySportsNews/status/1444597028286259203?ref_src=twsrc%5Etfw">October 3, 2021</a>
              </blockquote>
              <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
           </body>
        </html>
        """

        let webView = WKWebView(frame: .zero, configuration: configuration)
        webView.loadHTMLString(html, baseURL: nil)

Thanks!



from Recent Questions - Stack Overflow https://ift.tt/3r6IAWy
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations