This message was deleted.
# helpdesk
s
This message was deleted.
m
I based myself on this very interesting article. I made changes to my code, but it still doesn’t work. I have a
handleReady
function that is called on click, which initializes the “AudioContext” part and allows me to retrieve the
MediaStreamTrack
in the end.
Copy code
const handleReady = () => {
    if (audioElRef.current) {
      const now = new Date().getTime();
      const beatPosition =
        ((now - roomCreatedAt) / 1000) % BEAT_DURATION_IN_SECONDS;

      audioContextRef.current = new AudioContext();

      audioSourceNodeRef.current =
        audioContextRef.current.createMediaElementSource(audioElRef.current);
      audioDestinationNodeRef.current =
        audioContextRef.current.createMediaStreamDestination();

      audioSourceNodeRef.current.connect(audioDestinationNodeRef.current);
      audioSourceNodeRef.current.connect(audioContextRef.current.destination);

      publishedTrack.current =
        audioDestinationNodeRef.current.stream.getAudioTracks()[0];

      audioElRef.current.currentTime = Number(beatPosition) || 0;
      audioElRef.current.play();

      setReadyToGo(true);
    }
};
Next, I have a
handleStartPublishingClick
function that is executed when the user wants to publish their microphone and audio file. It works fine for the microphone, but the audio file is muted or paused since it emits no sound (even though it is playing on the publisher’s machine).
Copy code
const handleStartPublishingClick = async () => {
  currentRoom.localParticipant.setMicrophoneEnabled(true);

  if (publishedTrack.current) {
    console.log('publishedTrack.current', publishedTrack.current);
    currentRoom.localParticipant.publishTrack(publishedTrack.current, {
      name: 'beat',
      source: Track.Source.Unknown,
    });
  }
};
When I check the subscribed tracks using
useTracks
on the subscriber’s side, I can see that I am subscribed to 2 tracks (the person’s microphone and the person’s audio file), but I can’t hear the audio file...
d
m
Hello @dry-elephant-14928 thanks for your answer! I took a look at your example, and I did exactly the same. However, when I publish the track, I receive a warning: “silence detected on local audio track.” Additionally, I displayed the audio element by adding the
controls
attribute to it, and indeed, the element is there but it doesn’t play. As soon as I do
source.current = audioContext.createMediaElementSource(audioEl.current);
, the audio track is no longer played on the client side. Do you have any suggestions? Thank you very much for your time and help.
Good news, I’m back after several tests, and I managed to make it all work. For those it might help, here’s what I did: I had my AudioContext which was suspended, preventing me from playing the audio file correctly. I had to do:
Copy code
if (audioContext.state === 'suspended') {
  await audioContext.resume();
}
Just before connecting the source to the destination of my AudioContext. Furthermore, I was using the
<RoomAudioRenderer />
component to subscribe to and play all the tracks, but I realized that only the Microphone and ScreenShareAudio tracks were targeted during subscription. So, I replaced this component with a custom one, on which I retrieve the tracks I’m interested in using
useTracks()
.
🙌 1
d
Glad to hear that. Agreed RoomAudioRenderer is a bit confusing that it's only subscribing to microphone tracks. I think we'll need to change the behavior there. CC: @eager-zoo-16408 @polite-kilobyte-67570
👀 1
✅ 1