ant-media / Ant-Media-Server

Ant Media Server is a live streaming engine software that provides adaptive, ultra low latency streaming by using WebRTC technology with ~0.5 seconds latency. Ant Media Server is auto-scalable and it can run on-premise or on-cloud.
https://antmedia.io
Other
4.3k stars 636 forks source link

Method setAudioEnabled in Android doesn't work? #6809

Open huynguyen96419 opened 1 week ago

huynguyen96419 commented 1 week ago

Short description

I want to mute audio by using setAudioEnabled(false) but it's doesn't work. And how i mute audio in Android SDK?

Environment

Steps to reproduce

  1. When i click a button i used setAudioEnabled(false)
  2. Audio didn't mute

Expected behavior

Audio mute when i click button mute

Ask your questions on Ant Media Github Discussions

@Composable
fun StartLiveStream(
    context: Context,
    viewModel: WatchEventViewModel,
    urlStream: String?,
    roomId: String?
) {
//    var webRTCClientTest: IWebRTCClient? = null
    val webRTCClientTest = remember {
        mutableStateOf<IWebRTCClient?>(null)
    }
    val isEnableSound by viewModel.isEnableSound.collectAsState()

    val surfaceView = remember {
        SurfaceViewRenderer(context).apply {
            holder.addCallback(object : SurfaceHolder.Callback {
                // TODO: DatDang - Update url live stream
                override fun surfaceCreated(holder: SurfaceHolder) {
                    Log.d("Datdang", "surfaceCreated:")
                    webRTCClientTest.value = IWebRTCClient.builder()
                        .setActivity(context as Activity?)
                        .addRemoteVideoRenderer(this@apply)
                        .setServerUrl(urlStream)
                        .build()
                    webRTCClientTest.value?.play(roomId)
                }

                override fun surfaceChanged(
                    holder: SurfaceHolder,
                    format: Int,
                    width: Int,
                    height: Int
                ) {

                }

                override fun surfaceDestroyed(holder: SurfaceHolder) {
                    this@apply.release()
                }
            })
        }
    }
    // Apply audio setting whenever `isEnableSound` changes
    LaunchedEffect(isEnableSound) {
        webRTCClientTest.value?.setAudioEnabled(isEnableSound)
    }
    }
lastpeony commented 5 days ago

Hello, What do you mean by mute audio?

To mute microphone of your local participant please use toggleSendAudio

void toggleSendAudio(boolean enableAudio);

https://github.com/ant-media/WebRTC-Android-SDK/blob/82c093e124980d1e9e24233ddc07f0ac225c88aa/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/IWebRTCClient.java#L357

To mute incoming audio of all remote participants, use void toggleAudioOfAllParticipants(boolean enabled);

https://github.com/ant-media/WebRTC-Android-SDK/blob/82c093e124980d1e9e24233ddc07f0ac225c88aa/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/IWebRTCClient.java#L319

Also please ensure that you are using the latest SDK version.

burak-58 commented 1 day ago

Hi @huynguyen96419, Did you have a chance to try what @lastpeony suggested?

huynguyen96419 commented 8 hours ago

Hello, What do you mean by mute audio?

To mute microphone of your local participant please use toggleSendAudio

void toggleSendAudio(boolean enableAudio);

https://github.com/ant-media/WebRTC-Android-SDK/blob/82c093e124980d1e9e24233ddc07f0ac225c88aa/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/IWebRTCClient.java#L357

To mute incoming audio of all remote participants, use void toggleAudioOfAllParticipants(boolean enabled);

https://github.com/ant-media/WebRTC-Android-SDK/blob/82c093e124980d1e9e24233ddc07f0ac225c88aa/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/IWebRTCClient.java#L319

Also please ensure that you are using the latest SDK version.

You misunderstood my question. What I mean is the audio of the media when playing. I saw that the iOS SDK has a method called enableAudioTrack, but the Android SDK does not have that method. So I had to fork the library and make changes there.