Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2128 trigger pause when media component leaves view #194

Merged
merged 5 commits into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 1 addition & 0 deletions example.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"_useClosedCaptions": true,
"_startLanguage": "en",
"_allowFullScreen": true,
"_pauseWhenOffScreen": false,
"_showVolumeControl": true,
"_startVolume": "80%",
"_playsinline": false,
Expand Down
15 changes: 13 additions & 2 deletions js/adapt-contrib-media.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ define([
$(this.mediaElement).on({
'play': this.onMediaElementPlay,
'pause': this.onMediaElementPause,
'ended': this.onMediaElementEnded
'ended': this.onMediaElementEnded
danielstorey marked this conversation as resolved.
Show resolved Hide resolved
});

// occasionally the mejs code triggers a click of the captions language
Expand Down Expand Up @@ -286,6 +286,9 @@ define([

Adapt.trigger("media:stop", this);

var pauseWhenOffScreen = this.model.get('_pauseWhenOffScreen');
if (pauseWhenOffScreen) $(this.mediaElement).on('inview', this.onMediaElementInview);
moloko marked this conversation as resolved.
Show resolved Hide resolved

this.model.set({
'_isMediaPlaying': true,
'_isMediaEnded': false
Expand All @@ -299,6 +302,8 @@ define([
onMediaElementPause: function(event) {
this.queueGlobalEvent('pause');

$(this.mediaElement).off('inview', this.onMediaElementInview);

this.model.set('_isMediaPlaying', false);
},

Expand All @@ -312,6 +317,11 @@ define([
}
},

onMediaElementInview: function(event, isInView) {
if (isInView || event.currentTarget.paused) return;
event.currentTarget.pause();
danielstorey marked this conversation as resolved.
Show resolved Hide resolved
},

onMediaElementSeeking: function(event) {
var maxViewed = this.model.get("_maxViewed");
if(!maxViewed) {
Expand Down Expand Up @@ -428,7 +438,8 @@ define([
'pause': this.onMediaElementPause,
'ended': this.onMediaElementEnded,
'seeking': this.onMediaElementSeeking,
'timeupdate': this.onMediaElementTimeUpdate
'timeupdate': this.onMediaElementTimeUpdate,
'inview': this.onMediaElementInview
});

this.mediaElement.src = "";
Expand Down
8 changes: 8 additions & 0 deletions properties.schema
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down