# AudioTrack replacement issue on device change

**URL:** <https://openvidu.discourse.group/t/audiotrack-replacement-issue-on-device-change/4853>\
**Category:** Issues developing apps\
**Tags:** v2\
**Created:** [November 13, 2023, 7:30pm UTC](https://openvidu.discourse.group/t/audiotrack-replacement-issue-on-device-change/4853 "2023-11-13T19:30:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shri](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/shri/32/2311_2.png) [@Shri](https://openvidu.discourse.group/u/Shri)\
**Post date:** [November 13, 2023, 7:30pm UTC](https://openvidu.discourse.group/t/audiotrack-replacement-issue-on-device-change/4853/1 "2023-11-13T19:30:05Z")

</div>

Hello,

We are having an issue where when the user tries to change or connect to headphones while on call, the user gets disconnected from the session.

We also tried ondevicechange (navigator) to replace the audio track. However, replacing it to id ‘default’ does not seem to work either.

Is there a better solution to handle audio input device changes ? Find snippet below:

```auto
navigator.mediaDevices.ondevicechange = async (event) => {
    event.preventDefault();
    OV.getDevices().then(async (devices) => {
      const audioDevices = devices.filter((device) => device.kind === 'audioinput');

      const mediaStream = await OV.getUserMedia({
        audioSource: audioDevices[0].deviceId,
      });

      const audioTrack = mediaStream.getAudioTracks()[0];
      if (audioTrack.readyState === 'live') {
        publisher
          .replaceTrack(audioTrack)
          .then()
          .catch((error) => console.error('Error replacing track', error));
      }
    });
  };

```

Any help on this would be really helpful! Thanks in advance!

Shri
