Initial commit
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package com.ubt.jimu.blockly.feature.audio;
|
||||
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class AndroidManufacturer {
|
||||
public static final String ASUS = "asus";
|
||||
public static final String SAMSUNG = "samsung";
|
||||
public static final String VIVO = "vivo";
|
||||
public static final String XIAO_MI = "Xiaomi";
|
||||
|
||||
public static boolean match(String str) {
|
||||
if (TextUtils.isEmpty(str)) {
|
||||
return false;
|
||||
}
|
||||
return Build.MANUFACTURER.toLowerCase().equals(str.toLowerCase());
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
package com.ubt.jimu.blockly.feature.audio;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class AudioParams {
|
||||
public static final String AAC = ".aac";
|
||||
public static final String MP3 = ".mp3";
|
||||
public static final String WAV = ".wav";
|
||||
public static final String gpp = ".3gp";
|
||||
}
|
195
sources/com/ubt/jimu/blockly/feature/audio/AudioPlayer.java
Normal file
195
sources/com/ubt/jimu/blockly/feature/audio/AudioPlayer.java
Normal file
@@ -0,0 +1,195 @@
|
||||
package com.ubt.jimu.blockly.feature.audio;
|
||||
|
||||
import android.media.MediaPlayer;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class AudioPlayer {
|
||||
private static AudioPlayer player;
|
||||
private MediaPlayer mPlayer;
|
||||
private String source;
|
||||
private Timer timer;
|
||||
private final String TAG = AudioPlayer.class.getSimpleName();
|
||||
private boolean isPausing = false;
|
||||
private int progress = -1;
|
||||
|
||||
public interface IProgressListener {
|
||||
void onError();
|
||||
|
||||
void onFinished();
|
||||
}
|
||||
|
||||
private class MyTimerTask extends TimerTask {
|
||||
private long future;
|
||||
|
||||
public MyTimerTask(long j) {
|
||||
this.future = j;
|
||||
}
|
||||
|
||||
@Override // java.util.TimerTask, java.lang.Runnable
|
||||
public void run() {
|
||||
if (AudioPlayer.this.mPlayer == null || AudioPlayer.this.mPlayer.getCurrentPosition() < this.future) {
|
||||
return;
|
||||
}
|
||||
AudioPlayer.this.stop();
|
||||
AudioPlayer.this.timer.cancel();
|
||||
AudioPlayer.this.timer = null;
|
||||
}
|
||||
}
|
||||
|
||||
private AudioPlayer() {
|
||||
this.mPlayer = null;
|
||||
this.mPlayer = new MediaPlayer();
|
||||
this.mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { // from class: com.ubt.jimu.blockly.feature.audio.AudioPlayer.1
|
||||
@Override // android.media.MediaPlayer.OnCompletionListener
|
||||
public void onCompletion(MediaPlayer mediaPlayer) {
|
||||
Log.i(AudioPlayer.this.TAG, "onCompletion");
|
||||
}
|
||||
});
|
||||
this.mPlayer.setOnSeekCompleteListener(new MediaPlayer.OnSeekCompleteListener() { // from class: com.ubt.jimu.blockly.feature.audio.AudioPlayer.2
|
||||
@Override // android.media.MediaPlayer.OnSeekCompleteListener
|
||||
public void onSeekComplete(MediaPlayer mediaPlayer) {
|
||||
Log.i(AudioPlayer.this.TAG, "onSeekComplete");
|
||||
}
|
||||
});
|
||||
this.mPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() { // from class: com.ubt.jimu.blockly.feature.audio.AudioPlayer.3
|
||||
@Override // android.media.MediaPlayer.OnErrorListener
|
||||
public boolean onError(MediaPlayer mediaPlayer, int i, int i2) {
|
||||
Log.e(AudioPlayer.this.TAG, "播放onError:what=" + i + " extra=" + i2);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
this.mPlayer.setOnInfoListener(new MediaPlayer.OnInfoListener() { // from class: com.ubt.jimu.blockly.feature.audio.AudioPlayer.4
|
||||
@Override // android.media.MediaPlayer.OnInfoListener
|
||||
public boolean onInfo(MediaPlayer mediaPlayer, int i, int i2) {
|
||||
Log.e(AudioPlayer.this.TAG, "onInfo:what=" + i + " extra=" + i2);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static synchronized AudioPlayer getInstance() {
|
||||
AudioPlayer audioPlayer;
|
||||
synchronized (AudioPlayer.class) {
|
||||
if (player == null) {
|
||||
player = new AudioPlayer();
|
||||
}
|
||||
audioPlayer = player;
|
||||
}
|
||||
return audioPlayer;
|
||||
}
|
||||
|
||||
private void startTimer(long j) {
|
||||
Timer timer = this.timer;
|
||||
if (timer != null) {
|
||||
timer.cancel();
|
||||
}
|
||||
this.timer = new Timer();
|
||||
this.timer.schedule(new MyTimerTask(j), 0L, 50L);
|
||||
}
|
||||
|
||||
public long getAudioDuration(String str) {
|
||||
try {
|
||||
this.mPlayer.reset();
|
||||
this.mPlayer.setDataSource(str);
|
||||
this.mPlayer.prepare();
|
||||
return this.mPlayer.getDuration();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
public void pause() {
|
||||
try {
|
||||
this.progress = this.mPlayer.getCurrentPosition();
|
||||
this.isPausing = true;
|
||||
this.mPlayer.pause();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean play(String str) {
|
||||
if (!new File(str).exists()) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
this.mPlayer.reset();
|
||||
this.mPlayer.setDataSource(str);
|
||||
this.mPlayer.prepare();
|
||||
if (TextUtils.isEmpty(this.source)) {
|
||||
this.source = str;
|
||||
this.progress = -1;
|
||||
this.isPausing = false;
|
||||
} else if (this.source.equals(str)) {
|
||||
if (!this.isPausing) {
|
||||
this.source = str;
|
||||
this.progress = -1;
|
||||
this.isPausing = false;
|
||||
} else if (this.progress > -1) {
|
||||
this.mPlayer.seekTo(this.progress);
|
||||
this.progress = -1;
|
||||
this.isPausing = false;
|
||||
}
|
||||
}
|
||||
this.mPlayer.start();
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void release() {
|
||||
this.mPlayer.release();
|
||||
this.mPlayer = null;
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
try {
|
||||
this.source = null;
|
||||
this.mPlayer.stop();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean play(String str, final IProgressListener iProgressListener) {
|
||||
this.mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { // from class: com.ubt.jimu.blockly.feature.audio.AudioPlayer.5
|
||||
@Override // android.media.MediaPlayer.OnCompletionListener
|
||||
public void onCompletion(MediaPlayer mediaPlayer) {
|
||||
IProgressListener iProgressListener2 = iProgressListener;
|
||||
if (iProgressListener2 != null) {
|
||||
iProgressListener2.onFinished();
|
||||
}
|
||||
AudioPlayer.this.mPlayer.setOnCompletionListener(null);
|
||||
}
|
||||
});
|
||||
this.mPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() { // from class: com.ubt.jimu.blockly.feature.audio.AudioPlayer.6
|
||||
@Override // android.media.MediaPlayer.OnErrorListener
|
||||
public boolean onError(MediaPlayer mediaPlayer, int i, int i2) {
|
||||
Log.e(AudioPlayer.this.TAG, "MediaPlayer onError:what=" + i + " extra=" + i2);
|
||||
IProgressListener iProgressListener2 = iProgressListener;
|
||||
if (iProgressListener2 != null) {
|
||||
iProgressListener2.onError();
|
||||
}
|
||||
AudioPlayer.this.mPlayer.setOnErrorListener(null);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return play(str);
|
||||
}
|
||||
|
||||
public void play(String str, long j, IProgressListener iProgressListener) {
|
||||
if (!play(str, iProgressListener) || j <= 0) {
|
||||
return;
|
||||
}
|
||||
startTimer(j);
|
||||
}
|
||||
}
|
159
sources/com/ubt/jimu/blockly/feature/audio/AudioRecoder.java
Normal file
159
sources/com/ubt/jimu/blockly/feature/audio/AudioRecoder.java
Normal file
@@ -0,0 +1,159 @@
|
||||
package com.ubt.jimu.blockly.feature.audio;
|
||||
|
||||
import android.media.MediaRecorder;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.ubtech.utils.FileHelper;
|
||||
import java.io.File;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class AudioRecoder {
|
||||
private static AudioRecoder audioRecoder = null;
|
||||
public static boolean recoding = false;
|
||||
private String fileName;
|
||||
private MediaRecorder recorder;
|
||||
private final String TAG = AudioRecoder.class.getSimpleName();
|
||||
private int sampleRateInHz = 16000;
|
||||
private long lastRecordTime = 0;
|
||||
|
||||
private class RecorderInfoListener implements MediaRecorder.OnInfoListener {
|
||||
private RecorderInfoListener() {
|
||||
}
|
||||
|
||||
@Override // android.media.MediaRecorder.OnInfoListener
|
||||
public void onInfo(MediaRecorder mediaRecorder, int i, int i2) {
|
||||
if (i == 1) {
|
||||
Log.e(AudioRecoder.this.TAG, "OnInfo: MEDIA_RECORDER_INFO_UNKNOWN");
|
||||
return;
|
||||
}
|
||||
if (i == 800) {
|
||||
AudioRecoder.recoding = false;
|
||||
Log.e(AudioRecoder.this.TAG, "OnInfo: MEDIA_RECORDER_INFO_MAX_DURATION_REACHED");
|
||||
} else {
|
||||
if (i != 801) {
|
||||
return;
|
||||
}
|
||||
AudioRecoder.recoding = false;
|
||||
Log.e(AudioRecoder.this.TAG, "OnInfo: MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class RecorderOnErrorListener implements MediaRecorder.OnErrorListener {
|
||||
private RecorderOnErrorListener() {
|
||||
}
|
||||
|
||||
@Override // android.media.MediaRecorder.OnErrorListener
|
||||
public void onError(MediaRecorder mediaRecorder, int i, int i2) {
|
||||
AudioRecoder.recoding = false;
|
||||
Log.e(AudioRecoder.this.TAG, "录音失败:what=" + i + " extra=" + i2);
|
||||
File file = new File(AudioRecoder.this.fileName);
|
||||
if (file.exists()) {
|
||||
FileHelper.a(file.getParentFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private AudioRecoder() {
|
||||
}
|
||||
|
||||
private boolean aacLibRecord(String str) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean aacRecord(String str) throws Exception {
|
||||
try {
|
||||
release();
|
||||
File parentFile = new File(str).getParentFile();
|
||||
if (!parentFile.exists()) {
|
||||
parentFile.mkdirs();
|
||||
}
|
||||
this.fileName = str;
|
||||
this.recorder = new MediaRecorder();
|
||||
this.recorder.setAudioSource(1);
|
||||
this.recorder.setOutputFormat(6);
|
||||
this.recorder.setAudioEncoder(3);
|
||||
this.recorder.setAudioSamplingRate(8000);
|
||||
this.recorder.setAudioChannels(1);
|
||||
this.recorder.setOutputFile(str);
|
||||
this.recorder.setOnErrorListener(new RecorderOnErrorListener());
|
||||
this.recorder.setOnInfoListener(new RecorderInfoListener());
|
||||
this.recorder.prepare();
|
||||
this.recorder.start();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
onRecordFailed(str);
|
||||
e.printStackTrace();
|
||||
release();
|
||||
Log.e(this.TAG, "prepare() failed");
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized AudioRecoder getInstance() {
|
||||
AudioRecoder audioRecoder2;
|
||||
synchronized (AudioRecoder.class) {
|
||||
if (audioRecoder == null) {
|
||||
audioRecoder = new AudioRecoder();
|
||||
}
|
||||
audioRecoder2 = audioRecoder;
|
||||
}
|
||||
return audioRecoder2;
|
||||
}
|
||||
|
||||
private void onRecordFailed(String str) {
|
||||
File parentFile = new File(str).getParentFile();
|
||||
if (parentFile.exists()) {
|
||||
FileHelper.a(parentFile);
|
||||
try {
|
||||
FileHelper.a(parentFile);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return this.fileName;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
if (TextUtils.isEmpty(this.fileName)) {
|
||||
return null;
|
||||
}
|
||||
String str = this.fileName;
|
||||
String substring = str.substring(str.lastIndexOf(File.separator) + 1, this.fileName.length());
|
||||
return substring.substring(0, substring.lastIndexOf("."));
|
||||
}
|
||||
|
||||
public void release() {
|
||||
MediaRecorder mediaRecorder = this.recorder;
|
||||
if (mediaRecorder != null) {
|
||||
try {
|
||||
try {
|
||||
mediaRecorder.release();
|
||||
} catch (IllegalStateException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} finally {
|
||||
this.recorder = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean startRecord(String str) throws Exception {
|
||||
recoding = true;
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
if (currentTimeMillis - this.lastRecordTime < 500) {
|
||||
return false;
|
||||
}
|
||||
Log.i(this.TAG, "调用录音:" + str);
|
||||
this.lastRecordTime = currentTimeMillis;
|
||||
return aacRecord(str);
|
||||
}
|
||||
|
||||
public void stopRecod() {
|
||||
recoding = false;
|
||||
release();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user