diff --git a/package/spec/frontend/media/MediaPool_spec.js b/package/spec/frontend/media/MediaPool_spec.js index 8e8ee4472..9dcce53d7 100644 --- a/package/spec/frontend/media/MediaPool_spec.js +++ b/package/spec/frontend/media/MediaPool_spec.js @@ -148,6 +148,19 @@ describe('MediaPool', function() { expect(callback).toHaveBeenCalled(); }); + + it('stores previous src until reallocated', function () { + let pool = new MediaPool(); + let player = pool.allocatePlayer({playerType: MediaType.VIDEO}); + player.src('www.example.com/test.mp4'); + expect(player.getMediaElement().hasAttribute('src')).toBe(true); + + pool.unAllocatePlayer(player); + expect(player.previousSrc).toStrictEqual('www.example.com/test.mp4'); + + player = pool.allocatePlayer({playerType: MediaType.VIDEO}); + expect(player.previousSrc).toBeNull(); + }); }); describe('#blessAll', function() { diff --git a/package/src/frontend/VideoPlayer/mediaEvents.js b/package/src/frontend/VideoPlayer/mediaEvents.js index 2eaee849c..0208c637c 100644 --- a/package/src/frontend/VideoPlayer/mediaEvents.js +++ b/package/src/frontend/VideoPlayer/mediaEvents.js @@ -10,7 +10,7 @@ export const mediaEvents = function(player, context) { function triggerMediaEvent(name) { if (context) { events.trigger('media:' + name, { - fileName: player.currentSrc(), + fileName: player.previousSrc || player.currentSrc(), context: context, currentTime: player.currentTime(), duration: player.duration(), diff --git a/package/src/frontend/media/MediaPool.js b/package/src/frontend/media/MediaPool.js index e7bd29f07..95e7a700f 100644 --- a/package/src/frontend/media/MediaPool.js +++ b/package/src/frontend/media/MediaPool.js @@ -64,6 +64,7 @@ export class MediaPool { player.playerId = playerId || this.allocatedPlayers[playerType].length player.releaseCallback = onRelease; + player.previousSrc = null; return player; } @@ -79,6 +80,8 @@ export class MediaPool { let type = this.getMediaTypeFromEl(player.el()); this.allocatedPlayers[type] = this.allocatedPlayers[type].filter(p=>p!=player); + player.previousSrc = player.currentSrc(); + player.controls(false); player.getMediaElement().loop = false; player.playsinline(false);