代码拉取完成,页面将自动刷新
同步操作将从 rxmt/Test114 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
Adaptation of RxAndroidAudio(https://github.com/Piasy/RxAndroidAudio) to Harmony OS.An Audio encapsulation library, with part Rx support.
本项目是基于开源项目Piasy/RxAndroidAudio进行鸿蒙化的移植和开发的,可以通过地址https://github.com/Piasy/RxAndroidAudio 追踪到原安卓项目版本。
implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
。
(4.add implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
into build.gradle of the moudle you perfer.)mAudioRecorder = AudioRecorder.getInstance();
mAudioFile = new File(
Environment.getExternalStorageDirectory().getAbsolutePath() +
File.separator + System.nanoTime() + ".file.m4a");
Source source = new Source();
source.setRecorderAudioSource(Recorder.AudioSource.MIC);
AudioProperty audioProperty = new AudioProperty.Builder()
.setRecorderSamplingRate(AUDIO_SAMPLE_RATE_HZ)
.setRecorderBitRate(AUDIO_BIT_RATE_HZ)
.setRecorderAudioEncoder(Recorder.AudioEncoder.AAC)
.build();
StorageProperty storageProperty = new StorageProperty.Builder()
.setRecorderFile(mAudioFile)
.setRecorderMaxDurationMs(-1)
.setRecorderMaxFileSizeBytes(-1)
.build();
mAudioRecorder.prepareRecord(source, Recorder.OutputFormat.MPEG_4,
audioProperty, storageProperty);
mAudioRecorder.startRecord();
// ...
mAudioRecorder.stopRecord();
Playconfig 中可以设置音频源,设置音量,或者播放循环: With PlayConfig, to set audio file or audio resource, set volume, or looping:
mRxAudioPlayer.play(PlayConfig.file(audioFile).looping(true).build())
.subscribeOn(Schedulers.io())
.observeOn(HarmonySchedulers.mainThread())
.subscribe(new Observer<Boolean>() {
@Override
public void onSubscribe(final Disposable disposable) {
}
@Override
public void onNext(final Boolean aBoolean) {
// prepared
}
@Override
public void onError(final Throwable throwable) {
}
@Override
public void onComplete() {
// play finished
// NOTE: if looping, the Observable will never finish, you need stop playing
// onDestroy, otherwise, memory leak will happen!
}
});
PlayConfig.file(audioFile) // play a local file
//.res(getApplicationContext(), R.raw.audio_record_end) // or play a raw resource
.looping(true) // loop or not
.leftVolume(1.0F) // left volume,but harmony Player not support left volume and right volume separated.
.rightVolume(1.0F) // right volume,but harmony Player not support left volume and right volume separated.
.build(); // build this config and play!
mOutputFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +
File.separator + System.nanoTime() + ".stream.m4a");
mOutputFile.createNewFile();
mFileOutputStream = new FileOutputStream(mOutputFile);
mStreamAudioRecorder.start(new StreamAudioRecorder.AudioDataCallback() {
@Override
public void onAudioData(final byte[] data,final int size) {
if (mFileOutputStream != null) {
try {
mFileOutputStream.write(data, 0, size);
} catch (IOException e) {
e.printStackTrace();
}
}
}
@Override
public void onError() {
new EventHandler(EventRunner.getMainEventRunner()).postSyncTask(new Runnable() {
@Override
public void run() {
new ToastDialog(StreamAbility.this).setText("Record fail").setDuration(DIALOG_DURATION).show();
mBtnStart.setText("Start");
mIsRecording = false;
}
});
}
});
Observable.just(mOutputFile).subscribeOn(Schedulers.io()).subscribe(new Action1<File>() {
@Override
public void call(File file) {
try {
mStreamAudioPlayer.init();
FileInputStream inputStream = new FileInputStream(file);
int read;
while ((read = inputStream.read(mBuffer)) > 0) {
mStreamAudioPlayer.play(mBuffer, read);
}
inputStream.close();
mStreamAudioPlayer.release();
} catch (IOException e) {
e.printStackTrace();
}
}
});
mStreamAudioPlayer.play(
mAudioProcessor.process(mRatio, mBuffer, StreamAudioRecorder.DEFAULT_SAMPLE_RATE),
read);
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。