Skip to content

Commit

Permalink
conditionally toggle sound; fix autoplay pausing
Browse files Browse the repository at this point in the history
  • Loading branch information
cvan committed Aug 14, 2015
1 parent 7e0d599 commit 25e18a0
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ window.postMessage({controls: false}, '*')

If `autoplay` is not explicitly passed as a parameter, `autoplay` is enabled by default when video controls are hidden (i.e., `controls` is falsy).

### Ability to mute/unmute sound ###

Query-string key-value params:

[`http://localhost:8080/?sound=0&autoplay=1&video=http://cdn2.vrideo.com/prod_videos/v1/lSPg9ka_1080p_full.webm`](http://localhost:8080/?sound=0&autoplay=1&video=http://cdn2.vrideo.com/prod_videos/v1/lSPg9ka_1080p_full.webm)

`postMessage` to the page from the JS console (or from an iframe):

```js
window.postMessage({sound: 0}, '*')
```

## Possible Issues and Resolutions ##
###Unable to play video###
If you download and run the code yourself, you need to serve the content to localhost before you can view video (due to _cross origin issues_).
Expand Down
6 changes: 6 additions & 0 deletions js/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,18 @@ var manualRotation = quat.create(),
},

mute: function() {
if (video.muted) {
return;
}
video.muted = true;
window.muteButton.className = 'fa fa-volume-off icon';
window.muteButton.title = 'Unmute';
},

unmute: function() {
if (!video.muted) {
return;
}
video.muted = false;
window.muteButton.className = 'fa fa-volume-up icon';
window.muteButton.title = 'Mute';
Expand Down
13 changes: 12 additions & 1 deletion js/elevr-player.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ function initFromSettings(newSettings) {
autoplay: undefined,
controls: true,
loop: true,
sound: true,
projection: 'mono'
});

Expand All @@ -154,6 +155,12 @@ function initFromSettings(newSettings) {
}
}

if (settings.sound) {
controls.unmute();
} else {
controls.mute();
}

settings.projection = util.getCustomProjection(settings.projection);

if (projection !== settings.projection) {
Expand Down Expand Up @@ -199,12 +206,16 @@ function initFromSettings(newSettings) {

if (settings.autoplay) {
controls.play();
} else {
} else if (settings.autoplay === false) {
// If user did not explicitly set `autoplay`, don't pause unnecessarily.
window.video.pause();
}
}

window.addEventListener('hashchange', function() {
// Remove the querystring if there were custom parameters.
window.history.pushState('', document.title, window.location.pathname + window.location.hash);

initFromSettings(window.location.hash);
});

Expand Down
27 changes: 25 additions & 2 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,40 @@
});

Object.keys(params).forEach(function(key) {
if (typeof defaults[key] === 'string') {
// If the expected type of the default is a string,
// then leave the user input as is.
ret[key] = params[key];
return;
}

if (typeof defaults[key] === 'number') {
// If the expected type of the default is a number,
// then turn the user input into a number.
ret[key] = parseFloat(params[key]);
return;
}

if (params[key] === null) {
// 'null' means it exists in the params but there's no value.
ret[key] = true;
return;
}

val = String(params[key]).toLowerCase();
switch (val) {
case '0':
case 'false':
case 'no':
case 'off':
case 'undefined':
case 'null':
ret[key] = false;
break;
case 'null':
// If it's 'null', that means it exists in the params but there's no value.
case '1':
case 'true':
case 'yes':
case 'on':
ret[key] = true;
break;
default:
Expand Down

0 comments on commit 25e18a0

Please sign in to comment.