Vimeo ネットワーキング ライブラリを使用して Android アプリでビデオを再生するのに役立つ完全なコードを次に示します。
最終コードの提示
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://api.vimeo.com/me/videos/123456789
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();
}
});
}
}