steep-balloon-41261
09/12/2023, 12:29 PMmost-garage-49809
09/12/2023, 6:30 PMhandleReady function that is called on click, which initializes the “AudioContext” part and allows me to retrieve the MediaStreamTrack in the end.
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).
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...dry-elephant-14928
09/13/2023, 5:28 AMmost-garage-49809
09/13/2023, 8:21 AMcontrols 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.most-garage-49809
09/13/2023, 9:44 AMif (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().dry-elephant-14928
09/13/2023, 4:19 PM