问题
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();
}
});
}
}
回答1:
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
https://api.vimeo.com/me/videos/123456789
So the final code will be like this
final String uri = "https://api.vimeo.com/me/videos/123456789";
instead of this
final String uri = "https://player.vimeo.com/videos/123456789/config";
Here is my complete code that helps me to play the video in android app by using Vimeo networking library
Presenting the final 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
final String uri = "https://api.vimeo.com/me/videos/123456789";
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();
ArrayList<VideoFile> videoFiles = video.files;
Log.i("TAG1", "videoFiles " + videoFiles);
if (videoFiles != null && !videoFiles.isEmpty()) {
VideoFile videoFile = videoFiles.get(0); // you could sort these files by size, fps, width/height
String link = videoFile.getLink();
Log.i("TAG2", "link " + link);
// load link
// use the link to play the video by **EXO Player** or **Video View**
// Start your video player here
}
}
@Override
public void failure(VimeoError error) {
Log.i("TAG3", "vimeo error : " + error.getErrorMessage());
Toast.makeText(PlayActivity.this, "failure due to " + error.getErrorMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}
来源:https://stackoverflow.com/questions/64958276/getting-video-files-value-null-while-integrating-with-vimeo-networking-java-libr