Getting video files value null while integrating with Vimeo Networking java Library, to play the video by URI

帅比萌擦擦* 提交于 2020-12-07 07:39:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!