简体   繁体   中英

Using Videoview or mediaplayer to play http live streaming video is LAG

First,I built a small app using videoview to play hls video with mp4 format on Samsung galaxt S2.With SD quality, video was smooth.But with HD quality,video was lag. Then, I built a larger app to play hls video using same videoview or mediaplayer android. When i played video, video was lag with SD and HD quality.

In small app, I have a string array to store URLs. My app allows user to choose a URL and push a button to throw a activity to play video using videoview: Code using videoview in the small app :

        VideoView vd = (VideoView)findViewById(R.id.videoView1);
        MediaController mc = new MediaController(this);
        mc.setAnchorView(vd);
        Uri uri = Uri.parse(URL_link);
        vd.setMediaController(mc);
        vd.setVideoURI(uri);
        vd.start();

In larger app, I using listfragment to display all URls. User choose a URLs, then throw a activity to playvideo using videoview. Code in the activity:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_channel_detail);
    TextView tv = (TextView) findViewById(R.id.tvVideoPlayer);
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        channel_id = extras.getInt(ChannelDetailActivity.CHANNEL_ID);
    }
    tv.setText("Video is playing...");
}
@Override
protected void onStart() {
    super.onStart();
    getChannelInfo();
}
private void getChannelInfo( ) {
    TimeTVApiCaller.getInstance().getChannel(channel_id, this,
            new AjaxCallback<ChannelInfo>() {
                @Override
                public void callback(String url, ChannelInfo object,
                        AjaxStatus status) {
                    if (object != null) {
                        Urlvideo = object.getChannelUrls().get(0).getPath();
                        getURLfull(Urlvideo);
                    }
                }
            });
}
    //get a full URL
protected void getURLfull(String url)
{
    TimeTVApiCaller.getInstance().getChannelStream(url, this, new AjaxCallback<String>()
            {
               @Override
            public void callback(String url, String object,
                    AjaxStatus status) {
            String Urlfull = object.replace("\"", "");
            Urltoken = Urlfull;
           //Using the same videoview
            VideoView vd = (VideoView) findViewById(R.id.videoView1);
            MediaController mc = new MediaController(ChannelDetailActivity.this);
            mc.setAnchorView(vd);
            Uri uri = Uri.parse(Urltoken);
            vd.setMediaController(mc);
            vd.setVideoURI(uri);
            vd.start();
            //vd.requestFocus();
            }
            });
}
   }

I have two questions :

  1. Why videoview or mediaplayer play hls video is lag?

  2. How to custom videoview or mediaplayer to play hls video smoothly?

Each segment in HLS aka HTTP Live Streaming is typically 10 seconds.

The player measures the time it takes to get each segment, if it took too long it will try to pick a bandwidth where it can get a segment or more before it plays it. And the most common error is buffering delays. You should look in the log file to see what the player is doing when playing content.

If the above is not helpful, this might help.

I assume HD quality is at least 720p and more than 1.5 mbps bit stream with h.264/avc encoding. My best guess is that S2 Hardware doesn't support it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM