这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@cloudwebrtc
Copy link
Contributor

Refer to swift sdk for improvement. By default, setSpeakerphoneOn(true |false); will switch between Receiver or Speaker. It will still give priority to wired wired/bluetooth headphones if connected.

But you can ignore all wired/bluetooth headphones and force them to output from the speaker through forceSpeakerOutput: true.

@petodavid
Copy link

As I see room.setSpeakerOn is ignored and it does not use the speaker, but by setting the default room options its working, can you confirm this behavior?

    roomOptions: RoomOptions(
      enableVisualizer: true,
      defaultAudioOutputOptions: AudioOutputOptions(speakerOn: true),
    ),

@cloudwebrtc
Copy link
Contributor Author

cloudwebrtc commented Feb 5, 2025

@petodavid , fixed in this PR.

@cloudwebrtc cloudwebrtc merged commit f90275f into main Feb 5, 2025
8 checks passed
@cloudwebrtc cloudwebrtc deleted the fix/improve-speaker-switching-logic-for-ios branch February 5, 2025 02:26
@kinghanjiangxue
Copy link

kinghanjiangxue commented Feb 18, 2025

@cloudwebrtc
When I enter the room, I don't need to sound, I embed Unity to play the audio. Here's how I set it up:


final result = await liveChatRepository.joinRoom(
config: tokenConfig! , autoSubscribe: false, enableAudio: false);


@override
void enableMedia({bool?  enableAudio, bool?  enableVideo}) {
if (enableAudio ! = null) {
currentRoom? .localParticipant? .setMicrophoneEnabled(enableAudio);
currentRoom? .setSpeakerOn(true, forceSpeakerOutput: true);
}

if (enableVideo ! = null) {
currentRoom? .localParticipant? .setCameraEnabled(enableVideo);
}
}


newRoom = Room(
      roomOptions: RoomOptions(
        adaptiveStream: true,
        dynacast: true,
        enableVisualizer: true,
        defaultAudioPublishOptions: const AudioPublishOptions(
          name: 'eve_audio_track_name',
          audioBitrate: AudioPreset.musicHighQualityStereo,
        ),
        defaultAudioOutputOptions: const AudioOutputOptions(
          speakerOn: true,
        ),
   

I set it up here, too. No
I can use the speaker to play sound normally, but when I turn off the microphone, if the sound is playing at this time, the sound of the speaker suddenly becomes very small:
I set the speaker on here but it doesn't work, if I turn on the microphone and it works again. May I ask where I set the wrong, how to modify, thank you

@kinghanjiangxue
Copy link

@cloudwebrtc When I enter the room, I don't need to sound, I embed Unity to play the audio. Here's how I set it up:


final result = await liveChatRepository.joinRoom(
config: tokenConfig! , autoSubscribe: false, enableAudio: false);


@override
void enableMedia({bool?  enableAudio, bool?  enableVideo}) {
if (enableAudio ! = null) {
currentRoom? .localParticipant? .setMicrophoneEnabled(enableAudio);
currentRoom? .setSpeakerOn(true, forceSpeakerOutput: true);
}

if (enableVideo ! = null) {
currentRoom? .localParticipant? .setCameraEnabled(enableVideo);
}
}


newRoom = Room(
      roomOptions: RoomOptions(
        adaptiveStream: true,
        dynacast: true,
        enableVisualizer: true,
        defaultAudioPublishOptions: const AudioPublishOptions(
          name: 'eve_audio_track_name',
          audioBitrate: AudioPreset.musicHighQualityStereo,
        ),
        defaultAudioOutputOptions: const AudioOutputOptions(
          speakerOn: true,
        ),
   

I set it up here, too. No I can use the speaker to play sound normally, but when I turn off the microphone, if the sound is playing at this time, the sound of the speaker suddenly becomes very small: I set the speaker on here but it doesn't work, if I turn on the microphone and it works again. May I ask where I set the wrong, how to modify, thank you

I solved the problem and I found that:
When autoSubscribe=true, the audio system works because:
LiveKit keeps the audio system active
Even if the microphone is turned off, there is still a subscribed remote track to keep the audio system active
When we set autoSubscribe=false and cancel all subscriptions:
The audio system has no active track
As a result, the system may enter the low-power state, and the sound of the speaker becomes smaller.
You need to set
// Disable track playback, but keep the subscription status

track.disable();

This will allow you to use the speaker normally

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants