ios - reproductor - ¿Cómo puedo detectar si el atributo autoplay de HTML5 es compatible?
insertar video en html5 (9)
Aquí hay una solución alternativa que usa una devolución de llamada y almacenamiento de sesión para probar la compatibilidad con reproducción automática de video HTML5. Una vez que se realiza la prueba y existe el almacenamiento de la sesión, la verificación no se realiza nuevamente hasta la próxima sesión. Esto ahorra ejecutar esto cada vez que se carga una página. Utiliza un video clip en blanco de base64 y 1 segundo para probar el soporte de reproducción automática.
https://gist.github.com/nathansearles/271870d4100f0f045c5c
// isAutoplaySupported(callback);
// Test if HTML5 video autoplay is supported
isAutoplaySupported = function(callback) {
// Is the callback a function?
if (typeof callback !== ''function'') {
console.log(''isAutoplaySupported: Callback must be a function!'');
return false;
}
// Check if sessionStorage exist for autoplaySupported,
// if so we don''t need to check for support again
if (!sessionStorage.autoplaySupported) {
// Create video element to test autoplay
var video = document.createElement(''video'');
video.autoplay = true;
video.src = ''data:video/mp4;base64,AAAAIGZ0eXBtcDQyAAAAAG1wNDJtcDQxaXNvbWF2YzEAAATKbW9vdgAAAGxtdmhkAAAAANLEP5XSxD+VAAB1MAAAdU4AAQAAAQAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAACFpb2RzAAAAABCAgIAQAE////9//w6AgIAEAAAAAQAABDV0cmFrAAAAXHRraGQAAAAH0sQ/ldLEP5UAAAABAAAAAAAAdU4AAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAABAAAAAAoAAAAFoAAAAAAAkZWR0cwAAABxlbHN0AAAAAAAAAAEAAHVOAAAH0gABAAAAAAOtbWRpYQAAACBtZGhkAAAAANLEP5XSxD+VAAB1MAAAdU5VxAAAAAAANmhkbHIAAAAAAAAAAHZpZGUAAAAAAAAAAAAAAABMLVNNQVNIIFZpZGVvIEhhbmRsZXIAAAADT21pbmYAAAAUdm1o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HJkPW5vbmUgZmlsbGVyPTAgaXBfcmF0aW89MS40MCBhcT0xOjEuMDAAgAAAAG9liIQAFf/+963fgU3DKzVrulc4tMurlDQ9UfaUpni2SAAAAwAAAwAAD/DNvp9RFdeXpgAAAwB+ABHAWYLWHUFwGoHeKCOoUwgBAAADAAADAAADAAADAAAHgvugkks0lyOD2SZ76WaUEkznLgAAFFEAAAARQZokbEFf/rUqgAAAAwAAHVAAAAAPQZ5CeIK/AAADAAADAA6ZAAAADwGeYXRBXwAAAwAAAwAOmAAAAA8BnmNqQV8AAAMAAAMADpkAAAAXQZpoSahBaJlMCCv//rUqgAAAAwAAHVEAAAARQZ6GRREsFf8AAAMAAAMADpkAAAAPAZ6ldEFfAAADAAADAA6ZAAAADwGep2pBXwAAAwAAAwAOmAAAABdBmqxJqEFsmUwIK//+tSqAAAADAAAdUAAAABFBnspFFSwV/wAAAwAAAwAOmQAAAA8Bnul0QV8AAAMAAAMADpgAAAAPAZ7rakFfAAADAAADAA6YAAAAF0Ga8EmoQWyZTAgr//61KoAAAAMAAB1RAAAAEUGfDkUVLBX/AAADAAADAA6ZAAAADwGfLXRBXwAAAwAAAwAOmQAAAA8Bny9qQV8AAAMAAAMADpgAAAAXQZs0SahBbJlMCCv//rUqgAAAAwAAHVAAAAARQZ9SRRUsFf8AAAMAAAMADpkAAAAPAZ9xdEFfAAADAAADAA6YAAAADwGfc2pBXwAAAwAAAwAOmAAAABdBm3hJqEFsmUwIK//+tSqAAAADAAAdUQAAABFBn5ZFFSwV/wAAAwAAAwAOmAAAAA8Bn7V0QV8AAAMAAAMADpkAAAAPAZ+3akFfAAADAAADAA6ZAAAAF0GbvEmoQWyZTAgr//61KoAAAAMAAB1QAAAAEUGf2kUVLBX/AAADAAADAA6ZAAAADwGf+XRBXwAAAwAAAwAOmAAAAA8Bn/tqQV8AAAMAAAMADpkAAAAXQZv9SahBbJlMCCv//rUqgAAAAwAAHVE='';
video.load();
video.style.display = ''none'';
video.playing = false;
video.play();
// Check if video plays
video.onplay = function() {
this.playing = true;
};
// Video has loaded, check autoplay support
video.oncanplay = function() {
if (video.playing) {
sessionStorage.autoplaySupported = ''true'';
callback(true);
} else {
sessionStorage.autoplaySupported = ''false'';
callback(false);
}
};
} else {
// We''ve already tested for support
// use sessionStorage.autoplaySupported
if (sessionStorage.autoplaySupported === ''true'') {
callback(true);
} else {
callback(false);
}
}
}
// Usage: isAutoplaySupported(callback);
// Using a callback assures that support
// has been properly checked
isAutoplaySupported(function(supported) {
if (supported) {
// HTML5 Video Autoplay Supported!
console.log(''HTML5 Video Autoplay Supported!'');
} else {
// HTML5 Video Autoplay Not Supported :(
console.log(''HTML5 Video Autoplay Not Supported :('');
}
});
¿Cómo puedo detectar si el elemento de video HTML5 de un navegador admite reproducción automática?
En iOS Safari actual, por ejemplo, la reproducción automática está desactivada .
Actualización: ahora diseñé la página web de tal manera que funciona con independencia de si se admite la reproducción automática. Ahora, cuando se carga la página, se muestra un video de inicialización . En un iPad, al usuario se le presenta un gran botón de reproducción. Una vez que se ha activado la reproducción, el video está oculto. Luego, la reproducción del reproductor de video se puede controlar desde JavaScript, que es lo que realmente necesito.
La prueba automática de Modernizr tiene algunos problemas de confiabilidad, como se señala aquí: https://github.com/Modernizr/Modernizr/issues/1095
Puede detectar la compatibilidad de reproducción automática de video al verificar si el estado en pausa de un elemento de video cambia después de reproducirse mediante programación. Solo esto puede devolver falsos negativos en algunos navegadores móviles, por lo que se debe agregar una verificación Promesa para cubrir estos.
Este método funciona en todos los principales navegadores (de escritorio y móviles), excepto para Android <= 4.0 y Windows Phone, donde devuelve un falso negativo.
Aquí está la función de detección:
var supports_video_autoplay = function(callback) {
if (typeof callback !== "function") return false;
var v = document.createElement("video");
v.paused = true;
var p = "play" in v && v.play();
callback(!v.paused || ("Promise" in window && p instanceof Promise));
};
Uso:
supports_video_autoplay(function(supported) {
if (supported) {
// video autoplay supported!
} else {
// no video autoplay support :(
}
});
Prueba en vivo: https://codepen.io/paulorely/pen/QveEGy
La razón por la que el script anterior y la detección Modernizr no es confiable podría ser que no están pasando todas las restricciones que Apple hizo:
- El video debe ser silenciado
- El video debe estar configurado para jugar en línea
- El video debe tener un tamaño (0x0 px fallará)
- El video debe estar visible en la ventana gráfica (sin efectos de opacidad, mostrar: ninguno o visible: oculto)
Inventé un pequeño complemento jQuery para detectar la reproducción automática. Vea si es más confiable:
(function ($) {
$.extend({
''canVideoautoplay'' : function ( callback ) {
var testStarted = false;
try {
var playsinline = navigator.userAgent.match(/(iPhone|iPod)/g) ? (''playsInline'' in document.createElement(''video'')) : true;
if (!playsinline) {
return callback(false);
}
var src = ''data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZQAAA7RtZGF0AAACrAYF//+o3EXpvebZSLeWLNgg2SPu73gyNjQgLSBjb3JlIDE1MiByMTkgYmEyNDg5OSAtIEguMjY0L01QRUctNCBBVkMgY29kZWMgLSBDb3B5bGVmdCAyMDAzLTIwMTcgLSBodHRwOi8vd3d3LnZpZGVvbGFuLm9yZy94MjY0Lmh0bWwgLSBvcHRpb25zOiBjYWJhYz0xIHJlZj0zIGRlYmxvY2s9MTowOjAgYW5hbHlzZT0weDM6MHgxMTMgbWU9aGV4IHN1Ym1lPTcgcHN5PTEgcHN5X3JkPTEuMDA6MC4wMCBtaXhlZF9yZWY9MSBtZV9yYW5nZT0xNiBjaHJvbWFfbWU9MSB0cmVsbGlzPTEgOHg4ZGN0PTEgY3FtPTAgZGVhZHpvbmU9MjEsMTEgZmFzdF9wc2tpcD0xIGNocm9tYV9xcF9vZmZzZXQ9LTIgdGhyZWFkcz0zIGxvb2thaGVhZF90aHJlYWRzPTEgc2xpY2VkX3RocmVhZHM9MCBucj0wIGRlY2ltYXRlPTEgaW50ZXJsYWNlZD0wIGJsdXJheV9jb21wYXQ9MCBjb25zdHJhaW5lZF9pbnRyYT0wIGJmcmFtZXM9MyBiX3B5cmFtaWQ9MiBiX2FkYXB0PTEgYl9iaWFz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ZgAAABR2bWhkAAAAAQAAAAAAAAAAAAAAJGRpbmYAAAAcZHJlZgAAAAAAAAABAAAADHVybCAAAAABAAAB13N0YmwAAACXc3RzZAAAAAAAAAABAAAAh2F2YzEAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAoABaAEgAAABIAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY//8AAAAxYXZjQwFkAAv/4QAYZ2QAC6zZQo35IQAAAwAMAAADAs4PFCmWAQAGaOviSyLAAAAAGHN0dHMAAAAAAAAAAQAAABAAAAGAAAAAFHN0c3MAAAAAAAAAAQAAAAEAAACIY3R0cwAAAAAAAAAPAAAAAQAAAwAAAAABAAAHgAAAAAEAAAMAAAAAAQAAAAAAAAABAAABgAAAAAEAAAeAAAAAAQAAAwAAAAABAAAAAAAAAAEAAAGAAAAAAQAAB4AAAAABAAADAAAAAAEAAAAAAAAAAQAAAYAAAAABAAAGAAAAAAIAAAGAAAAAHHN0c2MAAAAAAAAAAQAAAAEAAAAQAAAAAQAAAFRzdHN6AAAAAAAAAAAAAAAQAAAC3gAAAA4AAAAMAAAADAAAAAwAAAAUAAAADQAAAAwAAAAMAAAAEwAAAA0AAAAMAAAADAAAABIAAAANAAAADAAAABRzdGNvAAAAAAAAAAEAAAAwAAAAYnVkdGEAAABabWV0YQAAAAAAAAAhaGRscgAAAAAAAAAAbWRpcmFwcGwAAAAAAAAAAAAAAAAtaWxzdAAAACWpdG9vAAAAHWRhdGEAAAABAAAAAExhdmY1Ny43Ny4xMDA='';
var $video = $(''<video src="''+src+''" controls playsinline muted width="20" height="20" style="position:fixed;z-index:1000;top:0;left:0"></video>'');
$(''body'').prepend($video);
testStarted = true;
$video[0].play();
$video[0].onplay = function() {
this.playing = true;
};
$video[0].oncanplay = function() {
if ($video[0].playing) {
callback(true);
} else {
callback(false);
}
$video[0].pause();
$video.remove();
};
} catch(e) {}
if (!testStarted) {
callback(false);
}
}
});
})(jQuery);
Puedes usarlo así:
$(function () {
$.canVideoautoplay(function ( canAutoplay ) {
alert(''Can we autoplay? '' + canAutoplay);
});
});
Me doy cuenta de que esta es una pregunta en video, y también se aplica al audio.
He creado una prueba de audio con la intención de cargarla en Moderizr con Modernizr.addTest()
.
Los resultados son sorprendentes y muy dependientes del estado de la plataforma y del sistema. Resulta que hay varios navegadores Android que admiten la reproducción automática. Quien sabe.
Al mirar a GitHub , me imagino que los chicos de Modernizr resolverán todo esto de manera más confiable y elegante que yo, si es que aún no lo han hecho. Parece reducirse a la sincronización. Uno pensaría que los navegadores nos arrojarían un hueso aquí. Quizás lo harán.
De todos modos, aquí está el enlace jsfiddle: Audio (). Prueba de reproducción automática .
Si bien hay código de pelusa en el ejemplo jsfiddle, aquí está el núcleo:
var supportsAutoplay = false; //assume
var audio = new Audio();
var waitTime;
audio.autoplay = true;
audio.volume = 0;
// this will only be triggered if autoplay works
audio.addEventListener(''play'', function () {
supportsAutoplay = true;
});
audio.src = testSrc; //see if the listener is listening
setTimeout( //wait for listener to run
function(){
return supportsAutoplay;
},
waitTime
);
Si bien no he visto uno con un setTimeout
distinto al anterior (los chicos de Modernizr hablan sobre ello), existen varias versiones de este código. Supongo que le daré crédito a Peter Coles . Tal vez es menos probable que su versión sufra problemas de sincronización.
Por lo que puedo decir, ni Modernizr ni Dive in HTML5''s guide de detección saben cómo detectar si se admite la autoplay
. (Aunque la página "Indetectables" de Modernizr tampoco muestra la autoplay
).
He aparecido una página de prueba que alerta sobre el valor de la propiedad de autoplay
en un elemento <audio>
recién creado, y tanto Safari en iOS 4.3 como Chrome 13 en Mac OS X devuelven false
(en lugar de undefined
, que es lo que IE 6 regresa).
Por lo tanto, desafortunadamente, su mejor opción podría ser recurrir a la detección del navegador y mantener su propia lista de los navegadores compatibles con la autoplay
.
Tal vez esto ayude a futuros googlers como yo: esta función crea / elimina un video y prueba para ver si puede reproducirse automáticamente. Luego establece una variable global "reproducción automática" en verdadero o falso. Prueba la compatibilidad con MP4 y webM, pero agregar más no sería difícil si fuera necesario (solo la base 64 codifica y agrega otra fuente). La variable de "retraso aceptable" es cuánto tiempo demorará razonablemente el dispositivo para comenzar a reproducir los videos de prueba. Con una combinación de ancho de banda / procesamiento limitado, a veces tiene sentido usar la solución de respaldo (sin reproducción automática), incluso si se admite la reproducción automática. Usualmente uso 100ms.
function detect_autoplay(acceptable_delay){
autoplay = false;
var autoplay_test_content = document.createElement(''video'');
//create mp4 and webm sources, 5s long
var mp4 = document.createElement(''source'');
mp4.src = "data:video/mp4;base64,AAAAFGZ0eXBNU05WAAACAE1TTlYAAAOUbW9vdgAAAGxtdmhkAAAAAM9ghv7PYIb+AAACWAAACu8AAQAAAQAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAnh0cmFrAAAAXHRraGQAAAAHz2CG/s9ghv4AAAABAAAAAAAACu8AAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAABAAAAAAFAAAAA4AAAAAAHgbWRpYQAAACBtZGhkAAAAAM9ghv7PYIb+AAALuAAANq8AAAAAAAAAIWhkbHIAAAAAbWhscnZpZGVBVlMgAAAAAAABAB4AAAABl21pbmYAAAAUdm1oZAAAAAAAAAAAAAAAAAAAACRkaW5mAAAAHGRyZWYAAAAAAAAAAQAAAAx1cmwgAAAAAQAAAVdzdGJsAAAAp3N0c2QAAAAAAAAAAQAAAJdhdmMxAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAFAAOABIAAAASAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGP//AAAAEmNvbHJuY2xjAAEAAQABAAAAL2F2Y0MBTUAz/+EAGGdNQDOadCk/LgIgAAADACAAAAMA0eMGVAEABGjuPIAAAAAYc3R0cwAAAAAAAAABAAAADgAAA+gAAAAUc3RzcwAAAAAAAAAB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uC/rKgnKGWgQfQANEBAAEQEAAYABhYL/QACIhgAPuC/rOgnKGWgQkdANEBAAEQEBRgAGFgv9AAIiGAAPuC/rOgnKGWgQprANEBAAEQEAAYABhYL/QACIhgAPuC/rKgnKGWgQu4ANEBAAEQEAAYABhYL/QACIhgAPuC/rOgnKGWgQ0FANEBAAEQEAAYABhYL/QACIhgAPuC/rOgnKGWgQ5TANEBAAEQEAAYABhYL/QACIhgAPuC/rKgnKGWgQ+gANEBAAEQEAAYABhYL/QACIhgAPuC/rOgnKGWgRDtANEBAAEQEAAYABhYL/QACIhgAPuC/rOgnKGWgRI7ANEBAAEQEAAYABhYL/QACIhgAPuC/rIcU7trQOC7jLOBALeH94EB8YIUzLuNs4IBTbeH94EB8YIUzLuNs4ICm7eH94EB8YIUzLuNs4ID6LeH94EB8YIUzLuNs4IFNbeH94EB8YIUzLuNs4IGg7eH94EB8YIUzLuNs4IH0LeH94EB8YIUzLuNs4IJHbeH94EB8YIUzLuNs4IKa7eH94EB8YIUzLuNs4ILuLeH94EB8YIUzLuNs4INBbeH94EB8YIUzLuNs4IOU7eH94EB8YIUzLuNs4IPoLeH94EB8YIUzLuNs4IQ7beH94EB8YIUzLuNs4ISO7eH94EB8YIUzBFNm3SPTbuMU6uEH0O2dVOsghTM";
//append sources to test video
autoplay_test_content.appendChild(webm);
autoplay_test_content.appendChild(mp4);
//set attributes -needs to be visible or IE squawks, so we move it way outside
autoplay_test_content.id = "base64_test_video";
autoplay_test_content.autoplay = true;
autoplay_test_content.style.position = "fixed";
autoplay_test_content.style.left = "5000px";
//add to DOM
document.getElementsByTagName("body")[0].appendChild(autoplay_test_content);
var base64_test_video = document.getElementById("base64_test_video");
//test for autoplay, 100 ms buffer
setTimeout(function(){
if(!base64_test_video.paused){
autoplay = true;
}
document.getElementsByTagName("body")[0].removeChild(autoplay_test_content);
},acceptable_delay);
}
detect_autoplay(100);
Tal vez lo encuentres útil. Combiné todos los comentarios sugeridos en este hilo en esta solución: https://github.com/kaufguy/autoplay-detector
Demostración aquí: https://kaufguy.github.io/autoplay-detector/
También lo restringí al juego en línea solamente.
var MUTE_DELAY_PORTION = 25;
var isAutoplaySupported = function (callback, timeout) {
var called = false;
if (!callback) {
return;
}
if (!isPlaysinline()) {
return callback({ autoplay: false, muted: false });
}
checkAutoplay(false, function () { testHandler(false); });
setTimeout(function () {
checkAutoplay(true, function () { testHandler(true); });
}, timeout / MUTE_DELAY_PORTION);
var testHandler = function (mute) {
if (!called) {
called = true;
callback({ autoplay: true, muted: mute });
}
};
setTimeout(function () {
if (!called) {
called = true;
callback({ autoplay: false, muted: false });
}
}, timeout);
};
var checkAutoplay = function (mute, callback) {
var video = document.createElement(''video'');
video.ontimeupdate = function () {
if (video.currentTime != 0) {
return callback();
}
;
};
video.autoplay = true;
video.muted = mute;
video.setAttribute(''webkit-playsinline'', ''webkit-playsinline'');
video.setAttribute(''playsinline'', ''playsinline'');
video.src = ''data:audio/mpeg;base64,/+MYxAAAAANIAUAAAASEEB/jwOFM/0MM/90b/+RhST//w4NFwOjf///PZu////9lns5GFDv//l9GlUIEEIAAAgIg8Ir/JGq3/+MYxDsLIj5QMYcoAP0dv9HIjUcH//yYSg+CIbkGP//8w0bLVjUP///3Z0x5QCAv/yLjwtGKTEFNRTMuOTeqqqqqqqqqqqqq/+MYxEkNmdJkUYc4AKqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq'';
video.style.display = ''none'';
video.load();
video.play();
return video;
};
var isPlaysinline = function () {
return navigator.userAgent.match(/(iPhone|iPod)/g) ? (''playsInline'' in document.createElement(''video'')) : true;
};
isAutoplaySupported(function(autoplayResult){
//do somthing
}, 400)
Funciona para mi...
Tal vez respondo un poco tarde pero solo pruebo una solución que funciona bien para mí:
var loadStarted = false;
video.onloadstart = function(){
loadStarted = true;
};
function checkRunning(){
if(!loadStarted) removeVideo();
}
setTimeout(checkRunning, 1000);
El setTimeout no es muy limpio, ¡pero la solución general es así de simple!
Un poco tarde para la fiesta, pero la solución aceptada parece obsoleta: Modernizr ahora implementó esta función, consulte https://github.com/Modernizr/Modernizr/blob/master/feature-detects/video/autoplay.js
Sin embargo, contiene ataques similares a las otras soluciones publicadas aquí, pero mientras los navegadores no expongan la disponibilidad de esta característica, esta parece ser la mejor solución por el momento.
Tenga en cuenta que esta es una prueba asíncrona disponible desde Modernizr 3, por lo que debe usar la siguiente sintaxis .on()
para su prueba:
Modernizr.on(''videoautoplay'', function(result){
if(result) {
alert(''video autoplay is supported'');
} else {
alert(''video autplay is NOT supported'');
}
});
Véalo usted mismo: http://codepen.io/anon/pen/VYoWWY?editors=001
La muestra anterior incluye Modernizr 3 con la detección de funciones ''videoautplay'' ( http://v3.modernizr.com/download/#-videoautoplay ).