Skip to content

Commit 2185eaf

Browse files
committed
CB-11314: avoid seeking on media without duration
1 parent a006da3 commit 2185eaf

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/android/AudioPlayer.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,9 @@ public void pausePlaying() {
384384
public void stopPlaying() {
385385
if ((this.state == STATE.MEDIA_RUNNING) || (this.state == STATE.MEDIA_PAUSED)) {
386386
this.player.pause();
387-
this.player.seekTo(0);
387+
if (this.player.getDuration() > 0) {
388+
this.player.seekTo(0);
389+
}
388390
LOG.d(LOG_TAG, "stopPlaying is calling stopped");
389391
this.setState(STATE.MEDIA_STOPPED);
390392
}
@@ -482,8 +484,12 @@ public float getDuration(String file) {
482484
public void onPrepared(MediaPlayer player) {
483485
// Listen for playback completion
484486
this.player.setOnCompletionListener(this);
485-
// seek to any location received while not prepared
486-
this.seekToPlaying(this.seekOnPrepared);
487+
488+
if (this.player.getDuration() > 0) {
489+
// seek to any location received while not prepared
490+
this.seekToPlaying(this.seekOnPrepared);
491+
}
492+
487493
// If start playing after prepared
488494
if (!this.prepareOnly) {
489495
this.player.start();

0 commit comments

Comments
 (0)