VideoView plays video from URL for too long

Hi, I am trying to run a video from a URL. I call dynamic videos by passing url. Most of the time, it takes too much time to start the video. Video file size varies from 3 to 10 mb. I tried the minimum size, but there is a problem there. there is no communication problem, I use a Wi-Fi network with good speed. I have a user under the code to run the video
        try{

            Uri video = Uri.parse(VideoURL);
            videoview.setVideoURI(video);
        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        videoview.requestFocus();
        videoview.setDrawingCacheEnabled(true);

        videoview.setOnPreparedListener(new OnPreparedListener() {
            public void onPrepared(MediaPlayer mp) {

                int height = mp.getVideoHeight();
                int width = mp.getVideoWidth();
                changeori(height, width);


            }
        });

public void changeori(int h,int w)
{
    if(h>w)
    {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        videoview.start();
    }
    else
    {
       setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
       videoview.start();
    }

}

+4
source share

Source: https://habr.com/ru/post/1608008/


All Articles