我在我的 android 应用程序中使用Vimeo 网络库通过使用 Vimeo 的官方库通过Video View播放视频。
我使用 Token 验证 API
代码的问题是它给了我videoFiles的空值。当我在代码注释之间给出下面提到的b格式的链接时
这是我的代码
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
我不知道我应该传递哪个 URI,所以我以 2 格式传递 URI
一)https://player.vimeo.com/videos/123456789
它从失败方法中抛出了错误
I/TAG5:Vimeo 错误:使用 JsonReader.setLenient(true) 在第 1 行第 1 列路径 $ 接受格式错误的 JSON
b) https://player.vimeo.com/videos/123456789/config
I/TAG1:视频:com.vimeo.networking.model.Video@0 I/TAG2:VideoFiles null
所以最后我使用链接 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();
}
});
}
}