<div dir="ltr">Hi All,<div><br></div><div> Actually an android application for playing music I used ffmpeg.I am using the following code for seeking the song in ffmpeg..</div><div><br></div><div>
<p class=""><span class=""><span class=""> </span><span class=""> </span><span class=""> </span><span class=""> </span></span><span class="">int</span><span class=""> defaultStreamIndex = av_find_default_stream_index(fmt_ctx);</span></p>
<p class=""><span class=""><span class=""> </span><span class=""> </span><span class=""> </span><span class=""> </span></span><span class="">int</span><span class=""> seekStreamIndex = (audio_stream_index != -1)? audio_stream_index : defaultStreamIndex;</span></p>
<p class=""><span class=""><span class=""> </span><span class=""> </span><span class=""> </span><span class=""> </span>int64_t seekTime = av_rescale_q(seekValue*AV_TIME_BASE, AV_TIME_BASE_Q,fmt_ctx->streams[seekStreamIndex]->time_base);</span></p>
<p class=""><span class=""><span class=""> </span><span class=""> </span><span class=""> </span><span class=""> </span>int64_t seekStreamDuration = fmt_ctx->streams[seekStreamIndex]->duration;</span></p>
<p class=""><span class=""><span class=""> </span><span class=""> </span><span class=""> </span><span class=""> </span> </span><span class="">int</span><span class=""> flags = AVSEEK_FLAG_BACKWARD;</span></p>
<p class=""><span class=""><span class=""> </span><span class=""> </span><span class=""> </span><span class=""> </span> </span><span class="">if</span><span class=""> (seekTime > 0 && seekTime < seekStreamDuration)</span></p>
<p class=""><span class=""><span class=""> </span><span class=""> </span><span class=""> </span><span class=""> </span><span class=""> </span> flags |= AVSEEK_FLAG_ANY;</span></p>
<p class=""><span class=""><span class=""> </span><span class=""> </span><span class=""> </span><span class=""> </span> </span><span class="">int</span><span class=""> ret = av_seek_frame(fmt_ctx, seekStreamIndex, seekTime,flags);</span></p>
<p class=""><span class=""><span class=""> </span><span class=""> </span><span class=""> </span><span class=""> </span> </span><span class="">if</span><span class=""> (ret < 0)</span></p>
<p class=""><span class=""><span class=""> </span><span class=""> </span><span class=""> </span><span class=""> </span><span class=""> </span> ret = av_seek_frame(fmt_ctx, seekStreamIndex, seekTime,AVSEEK_FLAG_ANY);</span></p>
<p class=""><span class=""><span class=""> </span><span class=""> </span><span class=""> </span><span class=""> </span> avcodec_flush_buffers(dec_ctx);</span></p><p class=""><span class="">The length of the seek bar is total duration in milliseconds..for ex:totalduration is 3:20</span></p>
<p class=""><span class="">then seekbar length will be 200.</span></p><p class=""><span class="">The above code is working for some of the songs..but for some songs If I seek the song to for ex:3:00 or 2:40 then the song lasts for 3:50(actually duration is 3:20).If I don't seek and play it normally it ends at correct position.So please suggest me in solving this problem.</span></p>
<p class="">Thanks & Regards,</p><p class="">Bitfield.</p></div></div>