How to play video URL inside android webview

后端 未结 10 1479
谎友^
谎友^ 2020-12-10 12:51

I want to play video url inside my application webview but when i am run the application it showing only white screen . i had read some post on this and i have used that cod

相关标签:
10条回答
  • 2020-12-10 13:17

    I know this is an old issue, I had the same problem some days back and surfing across internet I found this complete source that helped me a lot, and now i want to share with others, maybe can help others like me..

    https://github.com/cprcrack/VideoEnabledWebView

    0 讨论(0)
  • 2020-12-10 13:17

    I also got stuck with this issue. I got correct response from server, but couldn`t play video. After long time I found a solution here. Maybe, in future this link will be invalid. So, here is my correct code

    Uri video = Uri.parse("Your link should be in this place "); 
    mVideoView.setVideoURI(video); 
    
    mVideoView.setZOrderOnTop(true); //Very important line, add it to Your code
    mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { 
        @Override 
        public void onPrepared(MediaPlayer mediaPlayer) {
       // here write another part of code, which provides starting the video
    }}
    
    0 讨论(0)
  • 2020-12-10 13:22

    If tried others anwsers no work,maybe you can try this:

     if(Build.VERSION.SDK_INT>= Build.VERSION_CODES.LOLLIPOP){
            webview.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        }
    
    0 讨论(0)
  • 2020-12-10 13:24

    Add webview.setWebChromeClient(new WebChromeClient()); and to enable plugins for your video add:

      if (Build.VERSION.SDK_INT < 8) {
         webview.getSettings().setPluginsEnabled(true);
      }  
      else {
         webview.getSettings().setPluginState(PluginState.ON);
      }
    

    Hope this helps.

    0 讨论(0)
提交回复
热议问题