You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Attaching media and "The play() request was interrupted" error in Chrome #564
I have problem with example example code of attaching media. The trackAdded callback is always called twice - in both inbound and outbound calls. In the second call Chrome throws:
The play() request was interrupted by a new load request
My code works anyway, I hear interlocutor and he hears me.
I "fixed" this console error by running play() only in the second call:
As the link with the error says, the play call is promise-based, and all play/pause calls should be buffered. While I've seen this error/warning appear as well, I've never actually seen ill effects from it, but the fact that Google wants you to fix it means that behavior can change in the future. I'll leave this open as a reminder that we need to update the example code.
At least in Chrome 68.0.3440.106, when that event is first emitted by the Session, both RTCPeerConnection::getReceivers() and RTCPeerConnection::getSenders() are going to return empty arrays, causing MediaStreams with no tracks to be set as the srcObject of the <video> elements and play() being called. The promise returned by that play() is never being resolved (successful or otherwise).
Later, when the call is setup trackAdded is emitted again, we create a couple new MediaStreams, add the tracks, assign the srcObject and call play(). Because the previous call to play() never resolved, you see the error.
Assuming that emitting the trackAdded event after getUserMedia() successfully resolves is "correct," adding a check for the count of senders/receivers is all that is required to silence the error:
var remoteVideo = document.getElementById('remoteVideo');
var localVideo = document.getElementById('localVideo');
session.on('trackAdded', function() {
// We need to check the peer connection to determine which track was added
var pc = session.sessionDescriptionHandler.peerConnection;
// Gets remote tracks
var receivers = pc.getReceivers();
if (receivers.length) { // If we don't have receivers, don't do anything
var remoteStream = new MediaStream();
receivers.forEach(function(receiver) {
remoteStream.addTrack(receiver.track);
});
remoteVideo.srcObject = remoteStream;
remoteVideo.play();
}
// Gets local tracks
var senders = pc.getSenders();
if (senders.length) { // If we don't have senders, don't do anything
var localStream = new MediaStream();
senders.forEach(function(sender) {
localStream.addTrack(sender.track);
});
localVideo.srcObject = localStream;
localVideo.play();
}
});
Another option which is (at least in my opinion) a little more clear, and results in the localVideo element getting setup much more quickly:
var remoteVideo = document.getElementById('remoteVideo');
var localVideo = document.getElementById('localVideo');
session.on('SessionDescriptionHandler-created', function (sdh) {
sdh.on('userMedia', function (stream) {
localVideo.srcObject = new MediaStream(stream);
localVideo.play();
});
});
session.on('trackAdded', function() {
// We need to check the peer connection to determine which track was added
var pc = session.sessionDescriptionHandler.peerConnection;
// Gets remote tracks
var receivers = pc.getReceivers();
if (receivers.length) { // If we don't have receivers, don't do anything
var remoteStream = new MediaStream();
receivers.forEach(function (receiver) {
remoteStream.addTrack(receiver.track);
});
remoteVideo.srcObject = remoteStream;
remoteVideo.play();
}
});
I'm not sure that hooking the SessionDescriptionHandler-created event is ideal, but the SessionDescriptionHandlerObserver is a bit limited. In an ideal world, when it emitted trackAdded it would include the MediaStreamTrack as an argument, obviating the need to look at the RTCPeerConnection at all. I suppose that is the price you pay for an abstracted SessionDescriptionHandler.
FYI - This probably falls down when you start with audio only and try to add video later.
Hello everyone.
I had a problem when configuring a sip.js with my asterisk server.
When I make a call from 1 computer to another, then my sound goes only to 1 side, moreover, regardless of the environment. And the image is not transmitted, only 1 stop frame. I am not an expert in asterisk or a sip.js, but I did everything according to the instructions, and I can not understand what could be the problem?
#815 is a new implementation which I believe/hope addresses this issue.
In short, the new SDH has a localMediaStream property which always exists and you can add a listener to that MediaStream to watch for track adds and removes.
* The local media stream initially has no tracks, so the presence of tracks
* should not be assumed. Furthermore, tracks may be added or removed if the
* local media changes - for example, on upgrade from audio only to a video session.
* At any given time there will be at most one audio track and one video track
* (it's possible that this restriction may not apply to sub-classes).
* Use `MediaStream.onaddtrack` or add a listener for the `addtrack` event
* to detect when a new track becomes available:
* https://developer.mozilla.org/en-US/docs/Web/API/MediaStream/onaddtrack
As there was no response and we believe this is fixed, we are going to close the issue. Please test with 0.17.0 and re-open if there is still an issue there.
Activity
kingkasuo commentedon Jun 21, 2018
@jakub-zawislak Have you sovled this problem? I have same problem
kingkasuo commentedon Jun 21, 2018
Uncaught (in promise) DOMException: The play() request was interrupted by a new load request. https://goo.gl/LdLk22
jakub-zawislak commentedon Jun 21, 2018
I have only added
window.chrometo the if condition but I'm still not proud of this 😄james-criscuolo commentedon Jun 21, 2018
As the link with the error says, the play call is promise-based, and all play/pause calls should be buffered. While I've seen this error/warning appear as well, I've never actually seen ill effects from it, but the fact that Google wants you to fix it means that behavior can change in the future. I'll leave this open as a reminder that we need to update the example code.
We've got a function in our code:
Instead of calling play/pause/any audioElement function directly, you call this function instead.
tm1000 commentedon Jul 11, 2018
This also works if you just comment out "remoteAudio.play()". Audio is still heard on both ends
seanbright commentedon Aug 28, 2018
I believe this is caused by
SessionDescriptionHandlercallingtrackAdded()when the promise returned bygetUserMedia()promise is resolved.At least in Chrome 68.0.3440.106, when that event is first emitted by the
Session, bothRTCPeerConnection::getReceivers()andRTCPeerConnection::getSenders()are going to return empty arrays, causingMediaStreams with no tracks to be set as thesrcObjectof the<video>elements andplay()being called. The promise returned by thatplay()is never being resolved (successful or otherwise).Later, when the call is setup
trackAddedis emitted again, we create a couple newMediaStreams, add the tracks, assign thesrcObjectand callplay(). Because the previous call toplay()never resolved, you see the error.Assuming that emitting the
trackAddedevent aftergetUserMedia()successfully resolves is "correct," adding a check for the count of senders/receivers is all that is required to silence the error:seanbright commentedon Aug 28, 2018
Another option which is (at least in my opinion) a little more clear, and results in the
localVideoelement getting setup much more quickly:I'm not sure that hooking the
SessionDescriptionHandler-createdevent is ideal, but theSessionDescriptionHandlerObserveris a bit limited. In an ideal world, when it emittedtrackAddedit would include theMediaStreamTrackas an argument, obviating the need to look at theRTCPeerConnectionat all. I suppose that is the price you pay for an abstractedSessionDescriptionHandler.FYI - This probably falls down when you start with audio only and try to add video later.
Reported in the documentation repository.
Minifets commentedon May 6, 2019
Hello everyone.
I had a problem when configuring a sip.js with my asterisk server.
When I make a call from 1 computer to another, then my sound goes only to 1 side, moreover, regardless of the environment. And the image is not transmitted, only 1 stop frame. I am not an expert in asterisk or a sip.js, but I did everything according to the instructions, and I can not understand what could be the problem?
configs.zip
john-e-riordan commentedon May 27, 2020
Hi,
#815 is a new implementation which I believe/hope addresses this issue.
In short, the new SDH has a
localMediaStreamproperty which always exists and you can add a listener to thatMediaStreamto watch for track adds and removes.james-criscuolo commentedon Jul 6, 2020
As there was no response and we believe this is fixed, we are going to close the issue. Please test with 0.17.0 and re-open if there is still an issue there.
jakub-zawislak commentedon Dec 26, 2020
I have now migrated to the 0.18.1 and I have no errors. I used this code for attaching media