几乎所有的播放器都是基于ffmpeg,所以这就用ffmpeg 来说吧.
大家都只是stop其实做了几个处理,一个是暂停播放,另外一个就是将播放位置seek到0点上.
除了这些,其实内部在seek的时候将播放队列的buffer 全部都清空了.
为了不纸上谈兵,这里就贴一段ffplay的代码
if (is->seek_req) { int64_t seek_target= is->seek_pos; int64_t seek_min= is->seek_rel > 0 ? seek_target - is->seek_rel + 2: INT64_MIN; int64_t seek_max= is->seek_rel < 0 ? seek_target - is->seek_rel - 2: INT64_MAX; //FIXME the +-2 is due to rounding being not done in the correct direction in generation // of the seek_pos/seek_rel variables ret = avformat_seek_file(is->ic, -1, seek_min, seek_target, seek_max, is->seek_flags); if (ret < 0) { fprintf(stderr, "%s: error while seeking\n", is->ic->filename); }else{ if (is->audio_stream >= 0) { packet_queue_flush(&is->audioq); packet_queue_put(&is->audioq, &flush_pkt); } if (is->subtitle_stream >= 0) { packet_queue_flush(&is->subtitleq); packet_queue_put(&is->subtitleq, &flush_pkt); } if (is->video_stream >= 0) { packet_queue_flush(&is->videoq); packet_queue_put(&is->videoq, &flush_pkt); } } is->seek_req = 0; eof= 0; }
seek完之后调用flush把缓冲队列的所有内容清空,包括音频,视频,字幕等数据.