en: Negocio
Buenas noticias para los usuarios de la API de Youtube ya que hoy se han lanzado una serie de APIs y herramientas muy interesantes.
Entre lo más destacado de esta actualización tenemos: automatizaciones de subidas de vídeos, gestión de datos y personalización del reproductor flash.
Aún más afortunado seremos los desarrolladores de Php que podremos implementar algunas de estas funcionalidades: búsquedas y actualizaciones de vídeos, comentarios, playlists, pérfiles de usuarios, etc…
Para ello debemos usar PHP Client Library (distribuida por Zend) y que puedes descargarla fácilmente en esta dirección, como es habitual no faltará documentación y podremos encontrar respuestas en alguna de estas direcciones:
Esepecialmente interesante es la posibilidad de no utilizar el reproductor Flash que ofrecía el servicio cuando “embebías” un código HTML, ahora se podrá utilizar un reproductor mucho más básico y personalizable… el diseño de muchos sitios web lo agradecerá.
Para aquellos que quieran algo más… gracias a esta librería Javascript (registro gratuito) podrás controlar los diferentes eventos del reproductor a su antojo (play, pausa, sonido, duracion, etc…)
Este sería un ejemplo para “embeber” un video de Youtube cusando SWF Object (un recurso muy útil a la hora de embeber Flash):
<script type="text/javascript" src="swfobject.js"></script> <div id="ytapiplayer"> Necesitas una versión de Flash 8 o superior para ver este video </div> <script type="text/javascript"> var params = { allowScriptAccess: "always" }; var atts = { id: "myytplayer" }; swfobject.embedSWF( "http://www.youtube.com/v/VIDEO_ID&enablejsapi=1&playerapiid=ytplayer", "ytapiplayer", "425", "356", "8", null, null, params, atts); </script>
Aquí puedes ver un ejemplo de Simulación de controles del Reproductor de YouTube con Javascript
function updateHTML(elmId, value) { document.getElementById(elmId).innerHTML = value; }
function setytplayerState(newState) { updateHTML("playerstate", newState); }
function onYouTubePlayerReady(playerId) { ytplayer = document.getElementById("myytplayer"); setInterval(updateytplayerInfo, 250); updateytplayerInfo(); ytplayer.addEventListener("onStateChange", "onytplayerStateChange"); }
function onytplayerStateChange(newState) { setytplayerState(newState); }
function updateytplayerInfo() { updateHTML("bytesloaded", getBytesLoaded()); updateHTML("bytestotal", getBytesTotal()); updateHTML("videoduration", getDuration()); updateHTML("videotime", getCurrentTime()); updateHTML("startbytes", getStartBytes()); updateHTML("volume", getVolume()); }
// functions for the api calls function loadNewVideo(id, startSeconds) { if (ytplayer) { ytplayer.loadVideoById(id, startSeconds); } }
function cueNewVideo(id, startSeconds) { if (ytplayer) { ytplayer.cueVideoById(id, startSeconds); } }
function play() { if (ytplayer) { ytplayer.playVideo(); } }
function pause() { if (ytplayer) { ytplayer.pauseVideo(); } }
function stop() { if (ytplayer) { ytplayer.stopVideo(); } }
function getPlayerState() { if (ytplayer) { return ytplayer.getState(); } }
function seekTo(seconds) { if (ytplayer) { ytplayer.seekTo(seconds, true); } }
function getBytesLoaded() { if (ytplayer) { return ytplayer.getVideoBytesLoaded(); } }
function getBytesTotal() { if (ytplayer) { return ytplayer.getVideoBytesTotal(); } }
function getCurrentTime() { if (ytplayer) { return ytplayer.getCurrentTime(); } }
function getDuration() { if (ytplayer) { return ytplayer.getDuration(); } }
function getStartBytes() { if (ytplayer) { return ytplayer.getVideoStartBytes(); } }
function mute() { if (ytplayer) { ytplayer.mute(); } }
function unMute() { if (ytplayer) { ytplayer.unMute(); } }
function getEmbedCode() { alert(ytplayer.getVideoEmbedCode()); }
function getVideoUrl() { alert(ytplayer.getVideoUrl()); }
function setVolume(newVolume) { if (ytplayer) { ytplayer.setVolume(newVolume); } }
function getVolume() { if (ytplayer) { return ytplayer.getVolume(); } }
function clearVideo() { if (ytplayer) { ytplayer.clearVideo(); } }
Haz click en “Cargar Video” antes de comenzar a reproducir el video.
Para reproducir un vídeo diferente únicamente debes introducir el id del vídeo y hacer click en “Cargar Video” de nuevo.
// allowScriptAccess must be set to allow the Javascript from one // domain to access the swf on the youtube domain var params = { allowScriptAccess: "always", bgcolor: "#cccccc" }; // this sets the id of the object or embed tag to 'myytplayer'. // You then use this id to access the swf and make calls to the player's API var atts = { id: "myytplayer" }; swfobject.embedSWF("http://www.youtube.com/apiplayerbeta?enablejsapi=1&playerapiid=ytplayer", "ytapiplayer", "400", "300", "8", null, null, params, atts);
Reproducir | Pausa | Stop | Silenciar | Habilitar sonido