Play Vimeo video in Android , video url containing iframe

房东的猫 提交于 2020-06-23 04:41:26

问题


Hello i am working on android application in which i want to play vimeo videos , i am getting response from Api in json and playing video using webview and it is playing good , but the webview is displaying very small and the playing video is also small my problems are

  1. I want playing video width to be according to android device width. I can get it from Displaymetrics but how to set to iframe ?
  2. I want to inflate custom view of media controller for playing videos. Custom controller like play pause icon

I am getting this kind of url response from api

 <iframe src="https://player.vimeo.com/video/video_id" width="640" height="360" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>

at video_id i am getting the video id

Below is the code which i used

webView.setWebChromeClient(new WebChromeClient());
        webView.getSettings().setAllowFileAccess(true);
        webView.getSettings().setPluginState(WebSettings.PluginState.ON);
        webView.getSettings().setPluginState(WebSettings.PluginState.ON_DEMAND);
        webView.setWebViewClient(new WebViewClient());
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.getSettings().setUseWideViewPort(true);

        String data_html=getexplore_list.get(pos).getVideo_url();

        webView.loadDataWithBaseURL("http://vimeo.com", data_html, "text/html", "UTF-8", null); 

Please Provide any solution or link will be grateful


回答1:


use style in html,

String url = "<iframe src=\"" + videoUrl + "\" style=\"border: 0; width: 100%; height: 95%; padding:0px; margin:0px\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>";



回答2:


mViewHolder.webView.getSettings().setJavaScriptEnabled(true);
String yourData = "<div id='made-in-ny'></div>\n" +
            "\n" +
            "<script src='https://player.vimeo.com/api/player.js'></script>\n" +
            "<script>\n" +
            "    var options = {\n" +
            "        id: 59777392,\n" +
            "        width: 540,\n" +
            "        loop: true\n" +
            "    };\n" +
            "\n" +
            "    var player = new Vimeo.Player('made-in-ny', options);\n" +
            "\n" +
            "    player.setVolume(0);\n" +
            "\n" +
            "    player.on('play', function() {\n" +
            "        console.log('played the video!');\n" +
            "    });\n" +
            "</script>";
mViewHolder.webView.loadData(yourData, "text/html; charset=utf-8", "UTF-8");

change id and width. it is working.



来源:https://stackoverflow.com/questions/42576376/play-vimeo-video-in-android-video-url-containing-iframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!