Skip to content

Commit eade598

Browse files
committed
add playback method in Android part
1 parent 7c19297 commit eade598

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/android/com/emj365/plugins/AudioRecorderAPI.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@
66
import org.json.JSONArray;
77
import org.json.JSONException;
88
import android.media.MediaRecorder;
9+
import android.media.MediaPlayer;
10+
import android.media.AudioManager;
911
import android.os.CountDownTimer;
1012
import android.os.Environment;
1113
import android.content.Context;
1214
import java.util.UUID;
15+
import java.io.FileInputStream;
16+
import java.io.File;
17+
import java.io.IOException;
1318

1419
public class AudioRecorderAPI extends CordovaPlugin {
1520

@@ -66,6 +71,37 @@ public void onFinish() {
6671
return true;
6772
}
6873

74+
if (action.equals("playback")) {
75+
MediaPlayer mp = new MediaPlayer();
76+
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
77+
try {
78+
FileInputStream fis = new FileInputStream(new File(outputFile));
79+
mp.setDataSource(fis.getFD());
80+
} catch (IllegalArgumentException e) {
81+
e.printStackTrace();
82+
} catch (SecurityException e) {
83+
e.printStackTrace();
84+
} catch (IllegalStateException e) {
85+
e.printStackTrace();
86+
} catch (IOException e) {
87+
e.printStackTrace();
88+
}
89+
try {
90+
mp.prepare();
91+
} catch (IllegalStateException e) {
92+
e.printStackTrace();
93+
} catch (IOException e) {
94+
e.printStackTrace();
95+
}
96+
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
97+
public void onCompletion(MediaPlayer mp) {
98+
callbackContext.success("playbackComplete");
99+
}
100+
});
101+
mp.start();
102+
return true;
103+
}
104+
69105
return false;
70106
}
71107

0 commit comments

Comments
 (0)