mirror of
https://github.com/apache/cordova-android.git
synced 2025-03-16 08:21:04 +08:00
reset of seekOnPrepared changed to properly reset only once playback has begun
This commit is contained in:
parent
7352a309a0
commit
45c714cbb5
@ -98,9 +98,9 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
|||||||
this.audioFile = file;
|
this.audioFile = file;
|
||||||
|
|
||||||
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||||
this.tempFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/tmprecording.3gp";
|
this.tempFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/tmprecording.mp3";
|
||||||
} else {
|
} else {
|
||||||
this.tempFile = "/data/data/" + handler.cordova.getActivity().getPackageName() + "/cache/tmprecording.3gp";
|
this.tempFile = "/data/data/" + handler.cordova.getActivity().getPackageName() + "/cache/tmprecording.mp3";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -212,8 +212,8 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
|||||||
if (this.readyPlayer(file)) {
|
if (this.readyPlayer(file)) {
|
||||||
this.player.start();
|
this.player.start();
|
||||||
this.setState(STATE.MEDIA_RUNNING);
|
this.setState(STATE.MEDIA_RUNNING);
|
||||||
|
this.seekOnPrepared = 0; //insures this is always reset
|
||||||
} else {
|
} else {
|
||||||
//
|
|
||||||
this.prepareOnly = false;
|
this.prepareOnly = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -342,10 +342,13 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
|||||||
public void onPrepared(MediaPlayer player) {
|
public void onPrepared(MediaPlayer player) {
|
||||||
// Listen for playback completion
|
// Listen for playback completion
|
||||||
this.player.setOnCompletionListener(this);
|
this.player.setOnCompletionListener(this);
|
||||||
|
// seek to any location received while not prepared
|
||||||
|
this.seekToPlaying(this.seekOnPrepared);
|
||||||
// If start playing after prepared
|
// If start playing after prepared
|
||||||
if (!this.prepareOnly) {
|
if (!this.prepareOnly) {
|
||||||
this.player.start();
|
this.player.start();
|
||||||
this.setState(STATE.MEDIA_RUNNING);
|
this.setState(STATE.MEDIA_RUNNING);
|
||||||
|
this.seekOnPrepared = 0; //reset only when played
|
||||||
} else {
|
} else {
|
||||||
this.setState(STATE.MEDIA_STARTING);
|
this.setState(STATE.MEDIA_STARTING);
|
||||||
}
|
}
|
||||||
@ -353,10 +356,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
|||||||
this.duration = getDurationInSeconds();
|
this.duration = getDurationInSeconds();
|
||||||
// reset prepare only flag
|
// reset prepare only flag
|
||||||
this.prepareOnly = true;
|
this.prepareOnly = true;
|
||||||
// seek to any location received while not prepared
|
|
||||||
this.seekToPlaying(this.seekOnPrepared);
|
|
||||||
// reset seek location
|
|
||||||
this.seekOnPrepared = 0;
|
|
||||||
// Send status notification to JavaScript
|
// Send status notification to JavaScript
|
||||||
this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', " + MEDIA_DURATION + "," + this.duration + ");");
|
this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', " + MEDIA_DURATION + "," + this.duration + ");");
|
||||||
}
|
}
|
||||||
@ -471,7 +471,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
case MEDIA_LOADING:
|
case MEDIA_LOADING:
|
||||||
//cordova js is not aware of MEDIA_LOADING, so we send MEDIA_STARTING insntead
|
//cordova js is not aware of MEDIA_LOADING, so we send MEDIA_STARTING instead
|
||||||
Log.d(LOG_TAG, "AudioPlayer Loading: startPlaying() called during media preparation: " + STATE.MEDIA_STARTING.ordinal());
|
Log.d(LOG_TAG, "AudioPlayer Loading: startPlaying() called during media preparation: " + STATE.MEDIA_STARTING.ordinal());
|
||||||
this.prepareOnly = false;
|
this.prepareOnly = false;
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user