1、Seek函数:
avformat_seek_file(pFormatCtx, -1, INT64_MIN, relsecds, INT64_MAX, 0);
relsecds单位: int64_t
2、Seek后还需要清楚音频和视频的buffer:
avcodec_flush_buffers(avCodecContext);
注:此时需要给avCodecContext添加线程锁,有两个线程中用了,不然avcodec_send_packet
和avcodec_receive_frame也会操作avCodecContext,导致崩溃。
添加变量
bool pausing;
void JfFFmpeg::pause() {
if (playStatus != NULL){
playStatus->pausing = true;
}
if (audio != NULL){
audio->pause();
}
}
void JfFFmpeg::resume() {
if (playStatus != NULL){
playStatus->pausing = false;
}
if (audio != NULL){
audio->resume();
}
}
void *playVideo(void *data){
JfVideo *video = (JfVideo *)data;
while (video->playStatus != NULL && !video->playStatus->exit){
if (video->playStatus->seeking){
av_usleep(1000 * 100);
continue;
}
if (video->playStatus->pausing){//暂停状态
av_usleep(1000 * 100);
continue;
}
if (video->queue->getQueueSize() == 0){//加载状态
if (!video->playStatus->loading){
video->playStatus->loading = true;
video->callJava->onCallLoading(CHILD_THREAD, true);
LOGD("VIDEO加载状态");
}
av_usleep(1000 * 100);
continue;
} else {
if (video->playStatus->loading){
video->playStatus->loading = false;
video->callJava->onCallLoading(CHILD_THREAD, false);
LOGD("VIDEO播放状态");
}
}
...
}