SimpleExoPlayer seekTo not working
[REQUIRED] Issue description
Hello, I found that using ExoPlayerImpl public void seekTo(int windowIndex, long positionMs), In some audio links, Using seekTo is not working.
[REQUIRED] Reproduction steps
Use https://pro-audio.xiaoheiban.cn/201907/b38bed16-d36a-4847-b5f8-8ad04e263b4a.amr audio link
This audio is generated after the recording is completed.
mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
File file = FileUtils.getAudioRecordPath(0);
mediaRecorder.setOutputFile(file.getAbsolutePath());
mediaRecorder.prepare();
mediaRecorder.start();
When the music is playing,Using seekTo is not working.
val transportControls = mediaSessionConnection?.getTransportControls()
transportControls?.seekTo(progress)
Doing so is not being called to the player seekTo, I found that having a value returned seems to be wrong.
MediaSessionConnector
@Override
public void onSeekTo(long position) {
if (canDispatchToPlaybackController(PlaybackStateCompat.ACTION_SEEK_TO)) { // always false
playbackController.onSeekTo(player, position);
}
}
@Override
public long getSupportedPlaybackActions(Player player) {
if (player == null || player.getCurrentTimeline().isEmpty()) {
return 0;
} else if (!player.isCurrentWindowSeekable()) {
return BASE_ACTIONS;
}
...
player.isCurrentWindowSeekable() // always false
Then I want to call the player's seekTo directly.
simpleExoPlayer.seekTo()
After the discovery of seekTo, the audio will replay, starting from zero.
[REQUIRED] Version of ExoPlayer being used
com.google.android.exoplayer:exoplayer:2.9.6
com.google.android.exoplayer:exoplayer-ui:2.9.6
com.google.android.exoplayer:extension-mediasession:2.9.6
The mp3 file or the mp3 link works fine. Why does the file generated by the recording have this problem? It feels strange.
I hope to get your help, thank you
Please read the documentation, which contains an answer to this question.
https://exoplayer.dev/progressive.html#enabling-constant-bitrate-seeking
DefaultExtractorsFactory extractorsFactory =
new DefaultExtractorsFactory().setConstantBitrateSeekingEnabled(true);
ProgressiveMediaSource progressiveMediaSource =
new ProgressiveMediaSource.Factory(dataSourceFactory, extractorsFactory)
.createMediaSource(progressiveUri);
I solved the problem after reading the document, thank you very much. @ojw28