Page Visibility API / Prerendering
Determine if your app is visible or not:
document.addEventListener('visibilitychange ', function(e) {
console.log('hidden:' + document.hidden,
'state:' + document.visibilityState)
}, false);
Demo
Prerendering pages:
<link rel="prerender" href="http://example.org/index.html">
Demo
Know when you're connected
Status:
if (navigator.onLine ) {
console.log('ONLINE!');
} else {
console.log('Connection flaky');
}
Online/offline events:
window.addEventListener('online', function(e) {
// Re-sync data with server.
}, false);
window.addEventListener('offline', function(e) {
// Queue up events for server.
}, false);
Scheduled playback
var ctx = new window.webkit AudioContext ();
function playSound(arrayBuffer) { // Obtain arrayBuffer from XHR2.
ctx.decodeAudioData(arrayBuffer, function(buffer) {
var src = ctx.createBufferSource();
src.buffer = buffer;
src.looping = false;
src.connect(ctx.destination);
src.noteOn(0); // Play immediately.
}, function(e) {
console.log(e);
});
}
Shoot: Now
2s delay
Loopy
Stop
Fullscreen content
<video width="300" src="movie.webm" controls></video>
<button onclick="enterFullscreen()">Get Huge!</button>
function enterFullscreen() {
var elem = document.querySelector('body');
elem.onwebkitfullscreenchange = function(e) {
console.log("Entered fullscreen!");
elem.onwebkitfullscreenchange = onFullscreenExit;
};
elem.webkitRequestFullScreen ();
}
Demo
Fullscreen API
Control of the entire document and elements:
document.webkitIsFullScreen ( bool )
document.webkitCurrentFullScreenElement ( DOMElement )
document.webkitFullScreenKeyboardInputAllowed ( bool )
document.webkitCancelFullScreen();
Element.webkitRequestFullScreen();
//Element.webkitRequestFullScreenWithKeys();
Control of media elements:
MediaElement.webkitSupportsFullscreen ( bool )
MediaElement.webkitDisplayingFullscreen ( bool )
MediaElement.webkitEnterFullScreen()
MediaElement.webkitExitFullScreen()
Microphone & camera access
Prefixed as navigator.webkitGetUserMedia() in WebKit
window.URL.createObjectURL() is prefixed as window.webkitURL.createObjectURL() in WebKit
Needs --enable-media-stream flag in Chrome.
Video conferencing and peer-to-peer spec
Plugin-free camera, microphone, device access.
<video autoplay controls></video>
<input type="button" value="⚫" onclick="record(this)" id="start">
<input type="button" value="◼" onclick="stop(this)" id="stop" disabled>
var record = function(button) {
recorder = mediaStream.recorder();
};
var stop = function(button) {
mediaStream.stop();
recorder.getRecordedData(function(blob) {
// Upload blob using XHR2.
});
};
window.navigator.getUserMedia ('video', function(stream) {
document.querySelector('video').src = window.URL.createObjectURL(stream) ;
localMediaStream = stream;
}, function(e) {
console.log(e);
});