Commit d8ca40ab authored by sheteng's avatar sheteng

语音房间 2

parent a86b18f9
...@@ -60,8 +60,8 @@ public class NotificationsFragment extends Fragment { ...@@ -60,8 +60,8 @@ public class NotificationsFragment extends Fragment {
// Bundle bundle = new Bundle(); // Bundle bundle = new Bundle();
// bundle.putLong("channelId", id); // bundle.putLong("channelId", id);
// navController.navigate(R.id.navigation_channel_connect, bundle); // navController.navigate(R.id.navigation_channel_connect, bundle);
Intent intent = new Intent(getContext(),ConnectChannelActivity.class); Intent intent = new Intent(getContext(), ConnectChannelActivity.class);
intent.putExtra("channelId",id); intent.putExtra("channelId", id);
startActivity(intent); startActivity(intent);
} }
...@@ -215,6 +215,19 @@ public class NotificationsFragment extends Fragment { ...@@ -215,6 +215,19 @@ public class NotificationsFragment extends Fragment {
} }
}); });
binding.disableAudio.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CCIMClient.getInstance().setLocalAudio(false);
}
});
binding.enableAudio.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CCIMClient.getInstance().setLocalAudio(true);
}
});
binding.exitRoom.setOnClickListener(new View.OnClickListener() { binding.exitRoom.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
......
...@@ -10,7 +10,9 @@ public class ToastUtil { ...@@ -10,7 +10,9 @@ public class ToastUtil {
CCIMClient.getInstance().handler.post(new Runnable() { CCIMClient.getInstance().handler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
Toast.makeText(context,msg,Toast.LENGTH_SHORT).show(); if (context != null) {
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
}
} }
}); });
} }
......
...@@ -31,12 +31,32 @@ ...@@ -31,12 +31,32 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content"/> android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button <Button
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:text="退出房间" android:text="退出房间"
android:id="@+id/exit_room" android:id="@+id/exit_room"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content"/> android:layout_height="wrap_content"/>
<Button
android:text="禁言"
android:id="@+id/disableAudio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:layout_marginLeft="10dp"
android:text="放开禁言"
android:id="@+id/enableAudio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout> </LinearLayout>
<ListView <ListView
......
...@@ -681,7 +681,7 @@ public class CCIMClient { ...@@ -681,7 +681,7 @@ public class CCIMClient {
conf.url(audioServer); conf.url(audioServer);
conf.plugin(JanusPlugins.VIDEOROOM); conf.plugin(JanusPlugins.VIDEOROOM);
janusService = new JanusService(context, roomId, user, callback); janusService = new JanusService(context, roomId, user, callback);
janusService.start(context,conf); janusService.start(context, conf);
} }
/** /**
...@@ -693,6 +693,12 @@ public class CCIMClient { ...@@ -693,6 +693,12 @@ public class CCIMClient {
} }
} }
public void setLocalAudio(boolean enable) {
if (janusService != null) {
janusService.setLocalAudio(enable);
}
}
private JanusService janusService; private JanusService janusService;
public void logout() { public void logout() {
......
...@@ -30,6 +30,7 @@ import com.karumi.dexter.PermissionToken; ...@@ -30,6 +30,7 @@ import com.karumi.dexter.PermissionToken;
import com.karumi.dexter.listener.PermissionRequest; import com.karumi.dexter.listener.PermissionRequest;
import com.karumi.dexter.listener.multi.MultiplePermissionsListener; import com.karumi.dexter.listener.multi.MultiplePermissionsListener;
import org.webrtc.AudioTrack;
import org.webrtc.DataChannel; import org.webrtc.DataChannel;
import org.webrtc.EglBase; import org.webrtc.EglBase;
import org.webrtc.Logging; import org.webrtc.Logging;
...@@ -48,6 +49,7 @@ public class JanusService extends JanusDelegate { ...@@ -48,6 +49,7 @@ public class JanusService extends JanusDelegate {
private AudioRoomListener callback; private AudioRoomListener callback;
private AudioManager audioManager; private AudioManager audioManager;
private AudioTrack audioTrack;
public JanusService(Context context, Integer roomId, User user, AudioRoomListener callback) { public JanusService(Context context, Integer roomId, User user, AudioRoomListener callback) {
audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
...@@ -56,7 +58,7 @@ public class JanusService extends JanusDelegate { ...@@ -56,7 +58,7 @@ public class JanusService extends JanusDelegate {
this.callback = callback; this.callback = callback;
if (audioManager != null) { if (audioManager != null) {
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
audioManager.setSpeakerphoneOn(true); // audioManager.setSpeakerphoneOn(true);
} }
} }
...@@ -89,6 +91,12 @@ public class JanusService extends JanusDelegate { ...@@ -89,6 +91,12 @@ public class JanusService extends JanusDelegate {
} }
} }
public void setLocalAudio(boolean enable) {
if (audioTrack != null) {
audioTrack.setEnabled(enable);
}
}
@Override @Override
public void onClose() { public void onClose() {
...@@ -118,9 +126,10 @@ public class JanusService extends JanusDelegate { ...@@ -118,9 +126,10 @@ public class JanusService extends JanusDelegate {
} }
@Override @Override
public void onMediaChanged(MediaBundle media) { public void onMediaChanged(MediaBundle media) {
audioTrack = media.localAudioTrack();
} }
@Override @Override
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment