Skip to content

Commit

Permalink
New: Added event trigger (fixes: #264) (#265)
Browse files Browse the repository at this point in the history
Co-authored-by: Oliver Foster <[email protected]>
  • Loading branch information
joe-replin and oliverfoster authored Jul 20, 2023
1 parent cc3ea89 commit 61c2b8c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions js/mediaView.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class MediaView extends ComponentView {
'media:stop': this.onMediaStop
});

_.bindAll(this, 'onMediaElementPlay', 'onMediaElementPause', 'onMediaElementEnded', 'onMediaElementTimeUpdate', 'onMediaElementSeeking', 'onOverlayClick', 'onMediaElementClick', 'onWidgetInview');
_.bindAll(this, 'onMediaElementPlay', 'onMediaElementPause', 'onMediaElementEnded', 'onMediaVolumeChange', 'onMediaElementTimeUpdate', 'onMediaElementSeeking', 'onOverlayClick', 'onMediaElementClick', 'onWidgetInview');

// set initial player state attributes
this.model.set({
Expand Down Expand Up @@ -495,7 +495,8 @@ class MediaView extends ComponentView {
$(this.mediaElement).on({
play: this.onMediaElementPlay,
pause: this.onMediaElementPause,
ended: this.onMediaElementEnded
ended: this.onMediaElementEnded,
volumechange: this.onMediaVolumeChange
});

// occasionally the mejs code triggers a click of the captions language
Expand Down Expand Up @@ -593,6 +594,10 @@ class MediaView extends ComponentView {
}
}

onMediaVolumeChange(event) {
Adapt.trigger('media:volumeChange', this.model, this.mediaElement.muted, this.mediaElement.volume);
}

onWidgetInview(event, isInView) {
if (!isInView && !this.mediaElement.paused) this.mediaElement.player.pause();
}
Expand Down Expand Up @@ -701,7 +706,8 @@ class MediaView extends ComponentView {
pause: this.onMediaElementPause,
ended: this.onMediaElementEnded,
seeking: this.onMediaElementSeeking,
timeupdate: this.onMediaElementTimeUpdate
timeupdate: this.onMediaElementTimeUpdate,
volumechange: this.onMediaVolumeChange
});

this.mediaElement.src = '';
Expand Down

0 comments on commit 61c2b8c

Please sign in to comment.