简体   繁体   English

使用Videoview或Mediaplayer播放http实时流视频是LAG

[英]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. 首先,我用videoview构建了一个小应用程序,可以在三星galaxt S2上播放mp4格式的hls视频。标清质量可以使视频流畅;而高清质量可以使视频滞后。 Then, I built a larger app to play hls video using same videoview or mediaplayer android. 然后,我构建了一个更大的应用程序,以使用相同的videoview或mediaplayer android播放hls视频。 When i played video, video was lag with SD and HD quality. 当我播放视频时,视频在标清和高清质量方面落后。

In small app, I have a string array to store URLs. 在小型应用程序中,我有一个字符串数组来存储URL。 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 : 我的应用程序允许用户选择URL并按一个按钮以引发活动以使用videoview播放视频:在小型应用程序中使用videoview进行编码:

        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. 在较大的应用程序中,我使用listfragment显示所有URls。 User choose a URLs, then throw a activity to playvideo using videoview. 用户选择一个URL,然后抛出一个活动以使用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? 为什么videoview或mediaplayer播放hls视频是滞后的?

  2. How to custom videoview or mediaplayer to play hls video smoothly? 如何自定义videoview或mediaplayer以流畅地播放hls视频?

Each segment in HLS aka HTTP Live Streaming is typically 10 seconds. HLS aka HTTP Live Streaming中的每个段通常为10秒。

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. 我假设高清质量至少为720p,并且具有h.264 / avc编码的比特流超过1.5 mbps。 My best guess is that S2 Hardware doesn't support it. 我最好的猜测是S2硬件不支持它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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