How can we play/buffer only few minutes of a video in Android?

Deadly 提交于 2019-12-22 12:08:28

问题


I need to play first 2 mins of a video. Using onBufferingUpdate() i get the percentage that is buffered. But by the time onPrepared is called i get buffered % as 40. Which is more than 2 mins of a video. (Considering i have a video of 30 mins)

Is there any way i can play/buffer video for only 2 mins ?

Thanks.


回答1:


The buffer size is pre-set into the firmware. All you can do is keep tabs on how much the buffer is filled, and even that is just on a percentage basis. The size is set in frameworks/base/media/libstagefright/include/NuCachedSource2.h

check out this bug report on code.google.com.


Edit: You can get current position of the video by usingmVideoView.getCurrentPosition(); which will return you the current position in milliseconds and now you will have to use a AsynTask

private class myAsync extends AsyncTask<Void, Integer, Void>
{
    @Override
    protected Void doInBackground(Void... params) {
        mVideoView.start();            
        do {            
            try {
                if(mVideoView.getCurrentPosition() == TimeUnit.MINUTES.toMillis(yourMinutes)){
                    mVideoView.stop();
                }
            } catch (Exception e) {
            }
        } while (mVideoView.getCurrentPosition() != mVideoView.getDuration());
        return null;
    }

You can start the AsyncTask by using new myAsync().execute(); statement.



来源:https://stackoverflow.com/questions/25667689/how-can-we-play-buffer-only-few-minutes-of-a-video-in-android

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