Skip to content

Commit

Permalink
Merge pull request #8 from ant-media/fix-dash-auto-play
Browse files Browse the repository at this point in the history
Handle playback_not_allowed error in dash player
  • Loading branch information
mekya authored Feb 12, 2024
2 parents 06120ec + 70b8a56 commit 828f9c2
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/web_player.js
Original file line number Diff line number Diff line change
Expand Up @@ -945,11 +945,29 @@ export class WebPlayer {
}
});
this.dashPlayer.on(dashjs.MediaPlayer.events.PLAYBACK_ERROR, (event) => {
Logger.warn("dash playback error: " + event);
this.tryNextTech();
});
this.dashPlayer.on(dashjs.MediaPlayer.events.ERROR, (event) => {
Logger.warn("error: " + event);
this.tryNextTech();
});

this.dashPlayer.on(dashjs.MediaPlayer.events.PLAYBACK_NOT_ALLOWED, (event) => {
Logger.warn("dash playback not allowed: " + event);
this.handleDashPlayBackNotAllowed();
});
}

handleDashPlayBackNotAllowed() {
if (!this.forcePlayWithAudio) {
Logger.info("Try to play with muted audio");
this.dashPlayer.setMute(true);
this.dashPlayer.play();
}
else {
this.tryNextTech();
}
}

makeDashPlayerVisibleWhenInitialized() {
Expand Down
47 changes: 45 additions & 2 deletions test/embedded-player.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -949,9 +949,52 @@ describe("WebPlayer", function() {
result = player.sendWebRTCData("data");
expect(result).to.be.false;
expect(sendDataViaWebRTC.callCount).to.be.equal(1);
});


it("handleDashPlayBackNotAllowed", async function(){

this.timeout(10000);
var videoContainer = document.createElement("video_container");



var player = new WebPlayer({
streamId:"streamConfig",
}, videoContainer, null);


{
player.playOrder = ["dash"];
await player.initialize().then(()=> {

}).catch((err) => {
expect.fail("it should not fail because we skip videojs and dash is already loaded");
});
}

player.dashPlayer = window.dashjs.MediaPlayer().create();

var setMute = sinon.replace(player.dashPlayer, "setMute", sinon.fake());
var play = sinon.replace(player.dashPlayer, "play", sinon.fake());
var nextTech = sinon.replace(player, "tryNextTech", sinon.fake());

expect(player.forcePlayWithAudio).to.be.false;
player.handleDashPlayBackNotAllowed();
expect(setMute.calledOnce).to.be.true;
expect(play.calledOnce).to.be.true;
expect(nextTech.notCalled).to.be.true;

expect(setMute.calledWithExactly(true)).to.be.true;


player.forcePlayWithAudio = true;
player.handleDashPlayBackNotAllowed();
expect(setMute.calledOnce).to.be.true;
expect(play.calledOnce).to.be.true;
expect(nextTech.calledOnce).to.be.true;





});

Expand Down

0 comments on commit 828f9c2

Please sign in to comment.