From 1dcc4e6c2262e7c7a162c84078ee385ef803c485 Mon Sep 17 00:00:00 2001
From: frank <839789740@qq.com>
Date: Mon, 12 Feb 2018 20:58:41 +0800
Subject: [PATCH] =?UTF-8?q?=E6=8E=A8=E6=B5=81=E7=9B=B4=E6=92=AD=E8=AE=BE?=
=?UTF-8?q?=E7=BD=AE=E9=9D=99=E9=9F=B3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Live/src/main/cpp/live.c | 1 -
.../java/com/frank/live/Push/AudioPusher.java | 23 ++++++++++++++-----
.../java/com/frank/live/Push/LivePusher.java | 9 ++++++++
.../frank/ffmpeg/activity/LiveActivity.java | 21 +++++++++++++----
app/src/main/res/layout/activity_live.xml | 12 +++++++++-
app/src/main/res/values/strings.xml | 2 ++
6 files changed, 55 insertions(+), 13 deletions(-)
diff --git a/Live/src/main/cpp/live.c b/Live/src/main/cpp/live.c
index 760e596..45d6ad7 100644
--- a/Live/src/main/cpp/live.c
+++ b/Live/src/main/cpp/live.c
@@ -117,7 +117,6 @@ void *push_thread(void * args){
goto end;
}
RTMPPacket_Free(packet);
- LOGI("RTMP_SendPacket success...");
}
pthread_mutex_unlock(&mutex);
}
diff --git a/Live/src/main/java/com/frank/live/Push/AudioPusher.java b/Live/src/main/java/com/frank/live/Push/AudioPusher.java
index df84e03..426dca4 100644
--- a/Live/src/main/java/com/frank/live/Push/AudioPusher.java
+++ b/Live/src/main/java/com/frank/live/Push/AudioPusher.java
@@ -17,6 +17,7 @@ public class AudioPusher extends Pusher {
private boolean isPushing;
private int minBufferSize;
private LiveUtil liveUtil;
+ private boolean isMute;
AudioPusher(AudioParam audioParam, LiveUtil liveUtil){
this.liveUtil = liveUtil;
@@ -65,16 +66,26 @@ public class AudioPusher extends Pusher {
public void run() {
super.run();
audioRecord.startRecording();
- while (isPushing){
- byte[] audioBuffer = new byte[minBufferSize];
- int length = audioRecord.read(audioBuffer, 0, audioBuffer.length);
- if(length > 0){
-// Log.i("AudioPusher", "is recording...");
- liveUtil.pushAudioData(audioBuffer, length);
+ while (isPushing){//处于推流状态
+ if(!isMute){//如果不静音,才推音频流
+ byte[] audioBuffer = new byte[minBufferSize];
+ int length = audioRecord.read(audioBuffer, 0, audioBuffer.length);
+ if(length > 0){
+// Log.i("AudioPusher", "is recording...");
+ liveUtil.pushAudioData(audioBuffer, length);
+ }
}
}
audioRecord.stop();
}
}
+ /**
+ * 设置静音
+ * @param isMute 是否静音
+ */
+ void setMute(boolean isMute){
+ this.isMute = isMute;
+ }
+
}
diff --git a/Live/src/main/java/com/frank/live/Push/LivePusher.java b/Live/src/main/java/com/frank/live/Push/LivePusher.java
index cb1d684..c4a686b 100644
--- a/Live/src/main/java/com/frank/live/Push/LivePusher.java
+++ b/Live/src/main/java/com/frank/live/Push/LivePusher.java
@@ -59,4 +59,13 @@ public class LivePusher {
audioPusher.release();
liveUtil.release();
}
+
+ /**
+ * 设置静音
+ * @param isMute 是否静音
+ */
+ public void setMute(boolean isMute){
+ audioPusher.setMute(isMute);
+ }
+
}
diff --git a/app/src/main/java/com/frank/ffmpeg/activity/LiveActivity.java b/app/src/main/java/com/frank/ffmpeg/activity/LiveActivity.java
index 9907b14..14fe5ef 100644
--- a/app/src/main/java/com/frank/ffmpeg/activity/LiveActivity.java
+++ b/app/src/main/java/com/frank/ffmpeg/activity/LiveActivity.java
@@ -66,6 +66,7 @@ public class LiveActivity extends AppCompatActivity implements View.OnClickListe
private void initView(){
findViewById(R.id.btn_swap).setOnClickListener(this);
((ToggleButton)findViewById(R.id.btn_live)).setOnCheckedChangeListener(this);
+ ((ToggleButton)findViewById(R.id.btn_mute)).setOnCheckedChangeListener(this);
SurfaceView surface_camera = (SurfaceView) findViewById(R.id.surface_camera);
surfaceHolder = surface_camera.getHolder();
}
@@ -87,17 +88,27 @@ public class LiveActivity extends AppCompatActivity implements View.OnClickListe
@Override
public void onClick(View v) {
- if(v.getId() == R.id.btn_swap){
+ if(v.getId() == R.id.btn_swap){//切换摄像头
livePusher.switchCamera();
}
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- if(isChecked){
- livePusher.startPush(LIVE_URL, this);
- }else {
- livePusher.stopPush();
+ switch (buttonView.getId()){
+ case R.id.btn_live://开始/停止直播
+ if(isChecked){
+ livePusher.startPush(LIVE_URL, this);
+ }else {
+ livePusher.stopPush();
+ }
+ break;
+ case R.id.btn_mute://设置静音
+ Log.i(TAG, "isChecked=" + isChecked);
+ livePusher.setMute(isChecked);
+ break;
+ default:
+ break;
}
}
diff --git a/app/src/main/res/layout/activity_live.xml b/app/src/main/res/layout/activity_live.xml
index 6b5f8cc..cf4ba85 100644
--- a/app/src/main/res/layout/activity_live.xml
+++ b/app/src/main/res/layout/activity_live.xml
@@ -15,7 +15,8 @@
android:id="@+id/btn_swap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="@string/swap"/>
+ android:text="@string/swap"
+ android:layout_marginTop="20dp"/>
+
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index a2b1a01..685e894 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -35,5 +35,7 @@
切换
开始
停止
+ 静音
+ 声音