I used Vimeo Networking Library in my android app to play the video by Video View by useing the official library of Vimeo.
I authenticate the API with Token
The problem with the code is that it gives me the null value for the videoFiles. When I give the link in b format mentioned below between the code comment
Here is my code
public class PlayActivity extends AppCompatActivity {
VideoView videoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play);
videoView = findViewById(R.id.player);
// Getting access Token
String accessToken = getString(R.string.access_token);
Configuration.Builder configBuilder = new Configuration.Builder(accessToken)
.enableCertPinning(false);
//Vimeo Client autenticated
VimeoClient.initialize(configBuilder.build());
// the video uri; if you have a video, this is video.uri
I don't know which URI I should Pass, So I pass the URI in 2 format
a) https://player.vimeo.com/videos/123456789
It throws me the error from the failure method
I/TAG5: Vimeo error : Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $
b) https://player.vimeo.com/videos/123456789/config
I/TAG1: Video: com.vimeo.networking.model.Video@0 I/TAG2: VideoFiles null
So finally I use link b
final String uri = "https://player.vimeo.com/videos/123456789/config";
GsonDeserializer gsonDeserializer = new GsonDeserializer();
VimeoClient.getInstance().fetchNetworkContent(uri, new ModelCallback<Video>(Video.class) {
@Override
public void success(Video video) {
Toast.makeText(PlayActivity.this, "Sucessful" + video, Toast.LENGTH_SHORT).show();
Log.i("TAG1", "Video: " + video);
ArrayList<VideoFile> videoFiles = video.files;
Log.i("TAG2", "VideoFiles " + videoFiles);
// I am getting null Value of **videoFiles** and it's not passing the if block with link b above mentioned
if (videoFiles != null && !videoFiles.isEmpty()) {
VideoFile videoFile = videoFiles.get(0); // you could sort these files by size, fps, width/height
Log.i("TAG3", "VideoFiles " + videoFiles);
String link = videoFile.getLink();
Log.i("TAG4", "link " + link);
// load link
MediaController mediaController = new MediaController(PlayActivity.this);
mediaController.setAnchorView(videoView);
videoView.setVisibility(View.VISIBLE);
videoView.setVideoURI(Uri.parse(link));
videoView.setMediaController(null);
videoView.requestFocus();
videoView.start();
}
}
@Override
public void failure(VimeoError error) {
Log.i("TAG5", "vimeo error : " + error.getErrorMessage());
Toast.makeText(PlayActivity.this, "failure due to " + error.getErrorMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}
I just got the solution, thought of posting it here. So it can help other
The answer is straightforward, and I got the videoFile (TAG1) and link (TAG2) bypassing the link in this format
So the final code will be like this
instead of this
Here is my complete code that helps me to play the video in android app by using Vimeo networking library
Presenting the final code