推流直播设置静音

pull/107/head
frank 7 years ago
parent c84c32197b
commit 1dcc4e6c22
  1. 1
      Live/src/main/cpp/live.c
  2. 13
      Live/src/main/java/com/frank/live/Push/AudioPusher.java
  3. 9
      Live/src/main/java/com/frank/live/Push/LivePusher.java
  4. 13
      app/src/main/java/com/frank/ffmpeg/activity/LiveActivity.java
  5. 12
      app/src/main/res/layout/activity_live.xml
  6. 2
      app/src/main/res/values/strings.xml

@ -117,7 +117,6 @@ void *push_thread(void * args){
goto end;
}
RTMPPacket_Free(packet);
LOGI("RTMP_SendPacket success...");
}
pthread_mutex_unlock(&mutex);
}

@ -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,7 +66,8 @@ public class AudioPusher extends Pusher {
public void run() {
super.run();
audioRecord.startRecording();
while (isPushing){
while (isPushing){//处于推流状态
if(!isMute){//如果不静音,才推音频流
byte[] audioBuffer = new byte[minBufferSize];
int length = audioRecord.read(audioBuffer, 0, audioBuffer.length);
if(length > 0){
@ -73,8 +75,17 @@ public class AudioPusher extends Pusher {
liveUtil.pushAudioData(audioBuffer, length);
}
}
}
audioRecord.stop();
}
}
/**
* 设置静音
* @param isMute 是否静音
*/
void setMute(boolean isMute){
this.isMute = isMute;
}
}

@ -59,4 +59,13 @@ public class LivePusher {
audioPusher.release();
liveUtil.release();
}
/**
* 设置静音
* @param isMute 是否静音
*/
public void setMute(boolean isMute){
audioPusher.setMute(isMute);
}
}

@ -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,18 +88,28 @@ 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) {
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;
}
}
@Override

@ -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"/>
<ToggleButton
android:id="@+id/btn_live"
@ -25,4 +26,13 @@
android:textOff="@string/start"
android:layout_centerVertical="true"/>
<ToggleButton
android:id="@+id/btn_mute"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="@string/sound"
android:textOff="@string/mute"
android:layout_marginTop="20dp"
android:layout_alignParentEnd="true"/>
</RelativeLayout>

@ -35,5 +35,7 @@
<string name="swap">切换</string>
<string name="start">开始</string>
<string name="stop">停止</string>
<string name="mute">静音</string>
<string name="sound">声音</string>
</resources>

Loading…
Cancel
Save