Skip to content

Commit

Permalink
Merge pull request #2071 from tf/media-event-file-names
Browse files Browse the repository at this point in the history
Store previous src for media event file names
  • Loading branch information
tf authored Feb 7, 2024
2 parents ffb57cc + de94bf4 commit 17ab249
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
13 changes: 13 additions & 0 deletions package/spec/frontend/media/MediaPool_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion package/src/frontend/VideoPlayer/mediaEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
3 changes: 3 additions & 0 deletions package/src/frontend/media/MediaPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class MediaPool {

player.playerId = playerId || this.allocatedPlayers[playerType].length
player.releaseCallback = onRelease;
player.previousSrc = null;

return player;
}
Expand All @@ -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);
Expand Down

0 comments on commit 17ab249

Please sign in to comment.