1. 程式人生 > >MediaCodec seekto()後解碼播放視訊,花屏?

MediaCodec seekto()後解碼播放視訊,花屏?

通過 mVideoMediaExtractor.seekTo(mStartTimeStamp, MediaExtractor.SEEK_TO_CLOSEST_SYNC);

之後解碼通過SurfaceTexture播放視訊,有些時候花屏,如下是本人解決方法:

mVideoMediaExtractor.seekTo(mStartTimeStamp, MediaExtractor.SEEK_TO_CLOSEST_SYNC);

seekto 並不是嚴格等於期望mStartTimeStamp時間點,只是與之相近,需通過getSampleTime()重設該時間點.

if (mStartTimeStamp 
> 0) {
    mVideoMediaExtractor.seekTo(mStartTimeStamp, MediaExtractor.SEEK_TO_CLOSEST_SYNC);
//避免花屏long time = mVideoMediaExtractor.getSampleTime();
if
(time != -1) {
mStartTimeStamp = time;}
}
......
boolean doRender = mVideoDecodeBufferInfo.size !=0;
if ((mStartTimeStamp > 0 && currentDecodeTimeStamp < mStartTimeStamp
){ doRender = false; }
mVideoDecoder.releaseOutputBuffer(videoDecoderBufIndex, doRender);