question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Videos in a webview doesn't play

See original GitHub issue

Bug description: It is not possible to play any video in a webview. I have already tried videos from youtube (embedded, iframe, in an html file), vimeo … no video works, no image, no sound, just an inifinite loading. Opening the same link in the device’s default browser, the video starts playing. Opening the same link through the webview the page is loaded but the video doesn’t play.

Notes:

  • I added android:hardwareAccelerated="true" in androidManifest and <uses-permission android:name="android.permission.INTERNET"/>
  • I created a simple native example on android using webview and any video works without any problem.
  • I implemented a native ui component that when mounted starts a webview in an activity and it works.
  • If i put the code bellow in the Main Activity of my app it also works.
@Override
  @CallSuper
  protected void onCreate(@Nullable Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      webView = new WebView(this);
      setContentView(webView);

      WebSettings webSettings = webView.getSettings();
      webSettings.setJavaScriptEnabled(true);
      webSettings.setAllowFileAccess(true);

      webView.setWebViewClient(new WebViewClient() {
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
              return true;
          }
      });

      webView.setWebChromeClient(new WebChromeClient());
      webView.loadUrl("https://www.youtube.com/embed/TQsl9nxs_1o?autoplay=1");
  }
}

Environment:

  • Device: Fire TV Stick (Gen 2)
  • OS version: Fire OS 5
  • Android version : Android Level 22 (Android 5.1)
  • react-native version: 0.63.2
  • react-native-webview version: 10.8.3

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:34 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
Marinaarimanycommented, Oct 28, 2020

set as below mixedContentMode=‘always’

it works for me

3reactions
sidVaidyacommented, May 20, 2021

<WebView mediaPlaybackRequiresUserAction={true} androidLayerType= ‘hardware’ mixedContentMode=‘always’ style={{ height: 240, width: 320, alignSelf: “center”, alignContent: “center”, }} javaScriptEnabled={true} source={{ uri: https://www.youtube.com/embed/sFFwvr6l2mM? =0&autoplay=0&showinfo=0&controls=0&fullscreen=0 }} /> I have this code but only audio is playing video not visible

Read more comments on GitHub >

github_iconTop Results From Across the Web

Videos in a webview doesn't play · Issue #1632 · react-native ...
no video works, no image, no sound, just an inifinite loading. Opening the same link in the device's default browser, the video starts...
Read more >
Android webview cannot play video file error - Stack Overflow
Just tried your video url in my webview and it worked. Here are my settings: webView.getSettings().setJavaScriptEnabled(true); webView.
Read more >
Video from an embedded tweet doesn't play with WKWebView ...
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...
Read more >
Embedded Video not playing in WebView with iOS 13
You can try and either set the customUserAgent on the webview to something closer to the iPhone's default User-Agent so the HTML5 video...
Read more >
How to play audio/video in WebView from MemoryStream on ...
On Android, I'm using a custom WebViewClient to provide a MemoryStream in a ShouldInterceptRequest override for loaded resources. This works ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found