下载 WebRTC源码

在主机上执行 docker

docker run --rm \
						-v ${HOME}/下载/webrtc/webrtc/:/webrtc/ \
					   -it \
					  piasy/webrtc-build

以下均为在 docker 中执行

设置代理并开始下载代码
export http_proxy=192.168.3.195:9001
export https_proxy=192.168.3.195:9001
cd /depot_tools && git pull
cd /webrtc
fetch --nohooks webrtc_android
fetch 完成之后的效果

千万别在看到 Syncing projects: 100% (232/232), done. 时按 CTRL + C 键。

[1:06:22] Still working on:
[1:06:22] src/third_party/android_ndk
[1:06:32] Still working on:
[1:06:32] src/third_party/android_ndk
[1:06:34] Still working on:
[1:06:34] src/third_party/android_ndk
Syncing projects: 100% (232/232), done.
Running: git submodule foreach 'git config -f $toplevel/.git/config submodule.$name.ignore all'
Running: git config --add remote.origin.fetch '+refs/tags/*:refs/tags/*'
Running: git config diff.ignoreSubmodules all
执行 gsync
  • 修改 .gclient, 将 target_os = ["android", "unix"] 改为 target_os = ["android", "linux"]
cd /webrtc/ && vim .gclient

修改后内容为:

solutions = [
  {
    "url": "https://webrtc.googlesource.com/src.git",
    "managed": False,
    "name": "src",
    "deps_file": "DEPS",
    "custom_deps": {},
  },
]
target_os = ["android", "linux"]

  • 修改 .boto
cd /boot/ && vim .boto

修改后内容为:

[Boto]
proxy= http://192.168.3.195
proxy_port =9001
  • 设置环境变量
set NO_AUTH_BOTO_CONFIG=/root/.boto
执行 gclient sync
gclient sync
# 中间如果退出了,再次执行时不想重复下载以前的内容
gclient sync --nohooks
参考:

1.《WebRTC Native 开发实战》- 作者许建林
2.https://webrtc.github.io/webrtc-org/native-code/android/

这里是一个简单的 Android 录音机 Demo: 1. 在 Android Studio 中创建一个新项目,选择 Empty Activity 模板。 2. 在 app/build.gradle 文件中添加以下依赖项: ```groovy dependencies { implementation 'com.github.piasy:RxAndroidAudio:0.6.0' implementation 'com.github.piasy:DroidRepos:0.9.4' } ``` 3. 在布局文件中添加一个按钮和一个文本视图: ```xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/btn_record" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Record"/> <TextView android:id="@+id/tv_status" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/btn_record" android:layout_centerHorizontal="true" android:paddingTop="16dp"/> </RelativeLayout> ``` 4. 在 MainActivity.java 中添加以下代码: ```java public class MainActivity extends AppCompatActivity { private Button mBtnRecord; private TextView mTvStatus; private Disposable mDisposable; private MediaRecorder mMediaRecorder; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mBtnRecord = findViewById(R.id.btn_record); mTvStatus = findViewById(R.id.tv_status); mBtnRecord.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mDisposable != null && !mDisposable.isDisposed()) { mDisposable.dispose(); mDisposable = null; stopRecording(); } else { mDisposable = RxAndroidAudio .streamMediaRecorder(MainActivity.this, getOutputFile()) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Consumer<Integer>() { @Override public void accept(Integer integer) throws Exception { switch (integer) { case RxAndroidAudio.RxMediaRecorderState.MIC_ERROR: mTvStatus.setText("MIC_ERROR"); break; case RxAndroidAudio.RxMediaRecorderState.RECORDING: mTvStatus.setText("RECORDING"); break; case RxAndroidAudio.RxMediaRecorderState.MAX_DURATION_REACHED: mTvStatus.setText("MAX_DURATION_REACHED"); mDisposable.dispose(); mDisposable = null; stopRecording(); break; case RxAndroidAudio.RxMediaRecorderState.MAX_FILESIZE_REACHED: mTvStatus.setText("MAX_FILESIZE_REACHED"); mDisposable.dispose(); mDisposable = null; stopRecording(); break; case RxAndroidAudio.RxMediaRecorderState.STOP: mTvStatus.setText("STOP"); mDisposable.dispose(); mDisposable = null; stopRecording(); break; } } }); } } }); } private String getOutputFile() { File file = new File(getExternalFilesDir(null), "test.mp3"); if (file.exists()) { file.delete(); } return file.getAbsolutePath(); } private void stopRecording() { if (mMediaRecorder != null) { try { mMediaRecorder.stop(); mMediaRecorder.reset(); mMediaRecorder.release(); } catch (Exception e) { e.printStackTrace(); } } } } ``` 这个 Demo 使用了 RxAndroidAudio 库来录制音频,并使用 MediaRecorder 类来停止录制。当用户点击 Record 按钮时,该应用程序将开始录音,当用户再次点击 Record 按钮时,该应用程序将停止录音。在录制过程中,应用程序将在 TextView 上显示状态。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值