How to play vimeo video in android. I have tried using webview. Is there any other way to play vimeo video?

1.2k views Asked by At

I have tried playing vimeo video using webview. But it doesn't look good, it makes the screen scrollable. Vimeo has suggested one more way to play using native playback, but it has specific requirements to use

The basic requirements for native playback are:

  1. User must be logged in.
  2. User must be the owner of the video.
  3. User must be PRO or higher (or the app must have the "can access owner's video files" capability).
  4. Token must have the video_files scope. User must be the owner of the API app making the request

I don't have PRO account. How can i use native playback just to test, if all goes well then i will go for vimeo PRO

THIS IS CODE WHICH I AM USING FOR PLAYING USING WEBVIEW

 VimeoClient.getInstance().fetchNetworkContent(uri, new ModelCallback<Video>(Video.class) {
            @Override
            public void success(Video video) {
                String html = video.embed != null ? video.embed.html : null;
                if(html != null) {
                    WebView webView = (WebView) findViewById(R.id.webView);
                    WebSettings webSettings = webView.getSettings();
                    webSettings.setJavaScriptEnabled(true);
                    webView.loadData(html, "text/html", "utf-8");
                }
            }

            @Override
            public void failure(VimeoError error) {

                Log.d(TAG, "failure: ");
            }
        });
    }

Is there any other way to play the video?

1

There are 1 answers

6
Robiul Hossain Shah On

In my case I used Exoplayer. Exoplayer is more customizable. All you need is to extract the url link from the config link. You may use retrofit to extract the video url.

BASE_URL = "https://player.vimeo.com/video/"

You will need to use a get method like below:

@GET("{id}/{config}")
Call<JsonObject>getVideoLink(@Path("id") String id, @Path("config") String config);

You will get the id from video link. Example: "https://vimeo.com/123456789/" Here the id is: 123456789 .

 JsonObject jsonObject = response.body();
            JsonObject req = jsonObject.getAsJsonObject("request");
            JsonObject file = req.getAsJsonObject("files");
            JsonArray arr = file.getAsJsonArray("progressive");
            String url = arr.get(0).getAsJsonObject().get("url").getAsString();
           

Now you can play using this url . Don't forget to initiate Exoplayer first.