Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/android/AudioHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ else if (action.equals("getDurationAudio")) {
float f = this.getDurationAudio(args.getString(0), args.getString(1));
callbackContext.sendPluginResult(new PluginResult(status, f));
return true;
}
else if (action.equals("getBufferedPercentAudio")) {
int f = this.getBufferedPercentAudio(args.getString(0));
callbackContext.sendPluginResult(new PluginResult(status, f));
return true;
}
else if (action.equals("create")) {
String id = args.getString(0);
Expand Down Expand Up @@ -356,6 +361,19 @@ public float getDurationAudio(String id, String file) {
AudioPlayer audio = getOrCreatePlayer(id, file);
return audio.getDuration(file);
}

/**
* Get percentage of buffered data of playback.
* @param id The id of the audio player
* @return buffered data in percentage
*/
public int getBufferedPercentAudio(String id) {
AudioPlayer audio = this.players.get(id);
if (audio != null) {
return audio.getBufferedPercent();
}
return 0;
}

/**
* Set the audio device to be used for playback.
Expand Down
17 changes: 16 additions & 1 deletion src/android/AudioPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Licensed to the Apache Software Foundation (ASF) under one

import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnBufferingUpdateListener;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.media.MediaPlayer.OnPreparedListener;
Expand All @@ -43,7 +44,7 @@ Licensed to the Apache Software Foundation (ASF) under one
* android_asset: file name must start with /android_asset/sound.mp3
* sdcard: file name is just sound.mp3
*/
public class AudioPlayer implements OnCompletionListener, OnPreparedListener, OnErrorListener {
public class AudioPlayer implements OnCompletionListener, OnPreparedListener, OnErrorListener, OnBufferingUpdateListener {

// AudioPlayer modes
public enum MODE { NONE, PLAY, RECORD };
Expand Down Expand Up @@ -87,6 +88,8 @@ public enum STATE { MEDIA_NONE,
private boolean prepareOnly = true; // playback after file prepare flag
private int seekOnPrepared = 0; // seek to this location once media is prepared

private int bufferedPercent = 0;

/**
* Constructor.
*
Expand Down Expand Up @@ -542,6 +545,7 @@ private void loadAudioFile(String file) throws IllegalArgumentException, Securit
this.setMode(MODE.PLAY);
this.setState(STATE.MEDIA_STARTING);
this.player.setOnPreparedListener(this);
this.player.setOnBufferingUpdateListener(this);
this.player.prepareAsync();
}
else {
Expand Down Expand Up @@ -617,4 +621,15 @@ public float getCurrentAmplitude() {
}
return 0;
}

@Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
// TODO Auto-generated method stub
bufferedPercent = percent;

}

public int getBufferedPercent() {
return bufferedPercent;
}
}
11 changes: 11 additions & 0 deletions www/Media.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,17 @@ Media.prototype.getCurrentPosition = function(success, fail) {
}, fail, "Media", "getCurrentPositionAudio", [this.id]);
};

/**
* Get buffered percent of audio.
*/
Media.prototype.getBufferedPercent = function(success, fail) {
var me = this;
exec(function(p) {
me._position = p;
success(p);
}, fail, "Media", "getBufferedPercentAudio", [this.id]);
};

/**
* Start recording audio file.
*/
Expand Down