Play Vimeo video in Android , video url containing iframe
Asked Answered
O

2

1

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

Osanna answered 3/3, 2017 at 10:25 Comment(0)
C
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>";
Cercus answered 8/7, 2017 at 6:34 Comment(0)
C
1
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.

Cornhusk answered 16/10, 2017 at 5:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.