From 2185eaf482ac6bed7593c1a0ced184b71535c66e Mon Sep 17 00:00:00 2001 From: Stefan Schoettelndreyer Date: Tue, 24 May 2016 16:19:44 +0200 Subject: [PATCH] CB-11314: avoid seeking on media without duration --- src/android/AudioPlayer.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/android/AudioPlayer.java b/src/android/AudioPlayer.java index b40e281e..ddbf92b5 100644 --- a/src/android/AudioPlayer.java +++ b/src/android/AudioPlayer.java @@ -384,7 +384,9 @@ public void pausePlaying() { public void stopPlaying() { if ((this.state == STATE.MEDIA_RUNNING) || (this.state == STATE.MEDIA_PAUSED)) { this.player.pause(); - this.player.seekTo(0); + if (this.player.getDuration() > 0) { + this.player.seekTo(0); + } LOG.d(LOG_TAG, "stopPlaying is calling stopped"); this.setState(STATE.MEDIA_STOPPED); } @@ -482,8 +484,12 @@ public float getDuration(String file) { public void onPrepared(MediaPlayer player) { // Listen for playback completion this.player.setOnCompletionListener(this); - // seek to any location received while not prepared - this.seekToPlaying(this.seekOnPrepared); + + if (this.player.getDuration() > 0) { + // seek to any location received while not prepared + this.seekToPlaying(this.seekOnPrepared); + } + // If start playing after prepared if (!this.prepareOnly) { this.player.start();