1
0
mirror of https://github.com/videojs/video.js.git synced 2025-01-25 11:13:52 +02:00

Moving fullscreen to HTML5 api.

Forcing volume to between 0 and 1.
This commit is contained in:
Steve Heffernan 2010-12-09 15:44:56 -06:00
parent a67cc39c24
commit 6e05cb7082
4 changed files with 60 additions and 43 deletions

View File

@ -429,53 +429,19 @@ VideoJS.player.newBehavior("fullscreenToggle", function(element){
// When the user clicks on the fullscreen button, update fullscreen setting
onFullscreenToggleClick: function(event){
if (!this.videoIsFullScreen) {
this.fullscreenOn();
this.enterFullScreen();
} else {
this.fullscreenOff();
this.exitFullScreen();
}
},
// Turn on fullscreen (window) mode
// Real fullscreen isn't available in browsers quite yet.
fullscreenOn: function(){
if (!this.nativeFullscreenOn()) {
this.videoIsFullScreen = true;
// Storing original doc overflow value to return to when fullscreen is off
this.docOrigOverflow = document.documentElement.style.overflow;
// Add listener for esc key to exit fullscreen
_V_.addListener(document, "keydown", this.fullscreenOnEscKey.rEvtContext(this));
// Add listener for a window resize
_V_.addListener(window, "resize", this.fullscreenOnWindowResize.rEvtContext(this));
// Hide any scroll bars
document.documentElement.style.overflow = 'hidden';
// Apply fullscreen styles
_V_.addClass(this.box, "vjs-fullscreen");
// Resize the box, controller, and poster
this.positionAll();
}
},
// If available use the native fullscreen
nativeFullscreenOn: function(){
return (this.supportsFullScreen()) ? this.enterFullScreen() : false;
},
// Turn off fullscreen (window) mode
fullscreenOff: function(){
this.videoIsFullScreen = false;
document.removeEventListener("keydown", this.fullscreenOnEscKey, false);
window.removeEventListener("resize", this.fullscreenOnWindowResize, false);
// Unhide scroll bars.
document.documentElement.style.overflow = this.docOrigOverflow;
// Remove fullscreen styles
_V_.removeClass(this.box, "vjs-fullscreen");
// Resize the box, controller, and poster to original sizes
this.positionAll();
},
fullscreenOnWindowResize: function(event){ // Removeable
this.positionControlBars();
},
// Create listener for esc key while in full screen mode
fullscreenOnEscKey: function(event){ // Removeable
if (event.keyCode == 27) {
this.fullscreenOff();
this.exitFullScreen();
}
}
}

View File

@ -443,7 +443,8 @@ VideoJS.player.extend({
volume: function(percentAsDecimal){
if (percentAsDecimal !== undefined) {
this.values.volume = parseFloat(percentAsDecimal);
// Force value to between 0 and 1
this.values.volume = Math.max(0, Math.min(1, parseFloat(percentAsDecimal)));
this.video.volume = this.values.volume;
this.setLocalStorage("volume", this.values.volume);
return this;
@ -481,7 +482,8 @@ VideoJS.player.extend({
}
return false;
},
enterFullScreen: function(){
html5EnterNativeFullScreen: function(){
try {
this.video.webkitEnterFullScreen();
} catch (e) {
@ -489,6 +491,53 @@ VideoJS.player.extend({
}
return this;
},
// Turn on fullscreen (window) mode
// Real fullscreen isn't available in browsers quite yet.
enterFullScreen: function(){
if (this.supportsFullScreen()) {
this.html5EnterNativeFullScreen();
} else {
this.enterFullWindow();
}
},
exitFullScreen: function(){
if (this.supportsFullScreen()) {
// Shouldn't be called
} else {
this.exitFullWindow();
}
},
enterFullWindow: function(){
this.videoIsFullScreen = true;
// Storing original doc overflow value to return to when fullscreen is off
this.docOrigOverflow = document.documentElement.style.overflow;
// Add listener for esc key to exit fullscreen
_V_.addListener(document, "keydown", this.fullscreenOnEscKey.rEvtContext(this));
// Add listener for a window resize
_V_.addListener(window, "resize", this.fullscreenOnWindowResize.rEvtContext(this));
// Hide any scroll bars
document.documentElement.style.overflow = 'hidden';
// Apply fullscreen styles
_V_.addClass(this.box, "vjs-fullscreen");
// Resize the box, controller, and poster
this.positionAll();
},
// Turn off fullscreen (window) mode
exitFullWindow: function(){
this.videoIsFullScreen = false;
document.removeEventListener("keydown", this.fullscreenOnEscKey, false);
window.removeEventListener("resize", this.fullscreenOnWindowResize, false);
// Unhide scroll bars.
document.documentElement.style.overflow = this.docOrigOverflow;
// Remove fullscreen styles
_V_.removeClass(this.box, "vjs-fullscreen");
// Resize the box, controller, and poster to original sizes
this.positionAll();
},
onError: function(fn){ this.addVideoListener("error", fn); return this; },
onEnded: function(fn){

View File

@ -94,8 +94,10 @@ var VideoJS = JRClass.extend({
/* Local Storage
================================================================================ */
setLocalStorage: function(key, value){
try { localStorage[key] = value; }
catch(e) {
if (!localStorage) return;
try {
localStorage[key] = value;
} catch(e) {
if (e.code == 22 || e.code == 1014) { // Webkit == 22 / Firefox == 1014
this.warning(VideoJS.warnings.localStorageFull);
}

View File

@ -106,7 +106,7 @@
</p>
</div>
<!-- End VideoJS -->
<div class="video-js-box">
<!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody -->
<video data-subtitles="../demo-subtitles.srt" id="example_video_2" class="video-js" width="640" height="264" controls="controls" preload="none" poster="http://video-js.zencoder.com/oceans-clip.png">