diff --git a/README.md b/README.md index 4c31199c..224db4d3 100755 --- a/README.md +++ b/README.md @@ -50,6 +50,8 @@ guide the learner’s interaction with the component. **_allowFullScreen** (boolean): Determines whether fullscreen mode is available or not. Note that changing this setting has no effect in Internet Explorer 9 as this browser does not support fullscreen mode for HTML video. +**_pauseWhenOffScreen** (boolean): If set to true, pause playback when video is no longer in view. The default is `false`. + **_playsinline** (boolean): If set to `true`, videos will play 'inline' on iPhones (the same way they do on iPads). Note that this feature is only available in iOS10 and above. The default is `false`. **_preventForwardScrubbing** (boolean): If enabled, will attempt to prevent users from skipping ahead in media (audio/video) unless '_isComplete' is marked as 'true'. Users can skip backwards, and back up to the maxViewed time tracked by updateTime. Note: This does not apply to full screen iOS users and IE users may be able to circumvent this rule by using video play speed options in browser. diff --git a/bower.json b/bower.json index 66d0bc47..47bd818f 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "adapt-contrib-media", - "version": "4.0.1", + "version": "4.1.0", "framework": ">=3.3", "homepage": "https://github.com/adaptlearning/adapt-contrib-media", "issues": "https://github.com/adaptlearning/adapt_framework/issues/new", diff --git a/example.json b/example.json index e9f6e6e5..aac293e5 100644 --- a/example.json +++ b/example.json @@ -13,6 +13,7 @@ "_useClosedCaptions": true, "_startLanguage": "en", "_allowFullScreen": true, + "_pauseWhenOffScreen": false, "_showVolumeControl": true, "_startVolume": "80%", "_playsinline": false, diff --git a/js/adapt-contrib-media.js b/js/adapt-contrib-media.js index 12cfc71f..faba99a8 100755 --- a/js/adapt-contrib-media.js +++ b/js/adapt-contrib-media.js @@ -217,9 +217,9 @@ define([ // handle other completion events in the event Listeners $(this.mediaElement).on({ - 'play': this.onMediaElementPlay, - 'pause': this.onMediaElementPause, - 'ended': this.onMediaElementEnded + 'play': this.onMediaElementPlay, + 'pause': this.onMediaElementPause, + 'ended': this.onMediaElementEnded }); // occasionally the mejs code triggers a click of the captions language @@ -286,6 +286,8 @@ define([ Adapt.trigger("media:stop", this); + if (this.model.get('_pauseWhenOffScreen')) $(this.mediaElement).on('inview', this.onMediaElementInview); + this.model.set({ '_isMediaPlaying': true, '_isMediaEnded': false @@ -299,6 +301,8 @@ define([ onMediaElementPause: function(event) { this.queueGlobalEvent('pause'); + $(this.mediaElement).off('inview', this.onMediaElementInview); + this.model.set('_isMediaPlaying', false); }, @@ -312,6 +316,10 @@ define([ } }, + onMediaElementInview: function(event, isInView) { + if (!isInView && !event.currentTarget.paused) event.currentTarget.pause(); + }, + onMediaElementSeeking: function(event) { var maxViewed = this.model.get("_maxViewed"); if(!maxViewed) { @@ -428,7 +436,8 @@ define([ 'pause': this.onMediaElementPause, 'ended': this.onMediaElementEnded, 'seeking': this.onMediaElementSeeking, - 'timeupdate': this.onMediaElementTimeUpdate + 'timeupdate': this.onMediaElementTimeUpdate, + 'inview': this.onMediaElementInview }); this.mediaElement.src = ""; diff --git a/properties.schema b/properties.schema index fb92ad88..9bff23c1 100644 --- a/properties.schema +++ b/properties.schema @@ -190,6 +190,14 @@ "inputType": "Checkbox", "validators": [] }, + "_pauseWhenOffScreen": { + "type": "boolean", + "required": false, + "default": false, + "title": "Pause playback when video is no longer in view.", + "inputType": "Checkbox", + "validators": [] + }, "_playsinline": { "type": "boolean", "required": false,