Skip to content

Commit 1313861

Browse files
committed
CB-11314: avoid seeking on media without duration
1 parent 1425fec commit 1313861

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
@@ -340,7 +340,9 @@ public void pausePlaying() {
340340
public void stopPlaying() {
341341
if ((this.state == STATE.MEDIA_RUNNING) || (this.state == STATE.MEDIA_PAUSED)) {
342342
this.player.pause();
343-
this.player.seekTo(0);
343+
if (this.player.getDuration() > 0) {
344+
this.player.seekTo(0);
345+
}
344346
Log.d(LOG_TAG, "stopPlaying is calling stopped");
345347
this.setState(STATE.MEDIA_STOPPED);
346348
}
@@ -431,8 +433,12 @@ public float getDuration(String file) {
431433
public void onPrepared(MediaPlayer player) {
432434
// Listen for playback completion
433435
this.player.setOnCompletionListener(this);
434-
// seek to any location received while not prepared
435-
this.seekToPlaying(this.seekOnPrepared);
436+
437+
if (this.player.getDuration() > 0) {
438+
// seek to any location received while not prepared
439+
this.seekToPlaying(this.seekOnPrepared);
440+
}
441+
436442
// If start playing after prepared
437443
if (!this.prepareOnly) {
438444
this.player.start();

0 commit comments

Comments
 (0)