|
|
Labs.byHook |
Flash Scripts, Tools & Methods Developed at Hook |
There is nothing better than a little friendly competition, right? Mike came to me with the request to make his post a little more modular and into a javascript library that could be shared for the masses. Don’t get me wrong, I pretty much hate javascript unless it is wrapped by JQuery, but any opportunity to improve and take credit for another person’s hard work sounded too fantastic to pass up. So here is my update to Mike’s post — the BETTER way to implement video that is compatible with mobile phones, difficult browsers and HTML5-lovers/Flash-haters!
I apologize if my javascript coding techniques are not up to javascript-guru standards.
Although javascript is not a object-oriented language, I tried to write this class in a object-oriented way that allows for multiple instances on a page. The method is very simple to the experienced programmer and only takes a few lines of code to implement.
function init() { var video = new HTML5Video(); video.init({ outputElementId:'container', useFlashFirst:false, mobileVideoObject: new HTML5VideoObject(480,192, {"autobuffer":"autobuffer","controls":"controls"}), mobileH264: new HTML5VideoAsset("telematics_mobile.mp4","video/mp4"), mobilePosterImage: new HTML5VideoImage("telematics_mobile.jpg", 480, 192, "telematics", "No video playback capabilities."), androidPosterImage: new HTML5VideoImage("telematics_mobile_play.jpg", 480, 192), desktopVideoObject: new HTML5VideoObject(980, 390, {"autobuffer":"autobuffer","controls":"controls"}), desktopH264: new HTML5VideoAsset("telematics_desktop.mp4","video/mp4"), desktopAdditionalVideos: [new HTML5VideoAsset("telematics_desktop.ogv","video/ogg"), new HTML5VideoAsset("telematics_desktop.webm","video/webm")], desktopFlashObject: new HTML5VideoFlashObject("player.swf", 980, 414, {"allowFullScreen":"true", "flashvars":"file=telematics_desktop.flv&image=telematics_desktop.jpg"}), desktopPosterImage: new HTML5VideoImage("telematics_desktop.jpg", 980, 390, "telematics", "No video playback capabilities.") }); video.detect(); }
Now, most of the parameters should be pretty self-explanatory. However, there are a few objects that are used that need to be understood.
/* This object represents the actual video tag in HTML5. @param width Integer of the width of the video. @param height Integer of the height of the video. @param params Object of parameters that can be used on the video tag. Examples are: autoplay autoplay If present, then the video will start playing as soon as it is ready controls controls If present, controls will be displayed, such as a play button. loop loop If present, the video will start over again, every time it is finished. preload preload If present, the video will be loaded at page load, and ready to run. Ignored if "autoplay" is present. src url The URL of the video to play */ new HTML5VideoObject(480,192, {"autobuffer":"autobuffer","controls":"controls"}); /* This object represents the different sources for the HTML5 video object. @param src Source path to the video. @param type Type of video. Examples: video/mp4 video/ogg video/webm */ new HTML5VideoAsset("telematics_mobile.mp4","video/mp4"); /* This object represents the fallback image and the poster image for the video. @param src Source path to the image. @param width Integer of the width of the video. @param height Integer of the height of the video. @param alt Alt tag to the image @param title Title for the image */ new HTML5VideoImage("telematics_mobile.jpg", 480, 192, "telematics", "No video playback capabilities."); /* This object represents the flash object implementation. @param src Source path to the swf to load. @param width Integer of the width of the flash. @param height Integer of the height of the flash. @param params Object of parameters that can be used on the flash implementation. Examples are: flashvars Flash vars passed to the flash module: Example: "file=telematics_desktop.flv&image=telematics_desktop.jpg" allowFullScreen If present, controls will be displayed, such as a play button. wmode Window mode bgcolor Background color allowscriptaccess Whether to allow script access. See more: http://kb2.adobe.com/cps/127/tn_12701.html */ new HTML5VideoFlashObject("player.swf", 980, 414, {"allowFullScreen":"true", "flashvars":"file=telematics_desktop.flv&image=telematics_desktop.jpg"});
/*
outputElementId The string id of the HTML element to inject the code into. This method is used when the code is placed into the body of the page. Optionally, leaving this option out and placing the script tag inside the <body/> will output the code directly into that location. Note: <b>This only works using the "onload" method of implementation.</b>
useFlashFirst This is an optional boolean value for flash lovers that will use flash before using HTML5 as a fallback. Defaults to false (don't tell my flash coworkers). Also, this option requires the adobe detection kit js file. See example below.
mobileVideoObject A video object for mobile users (ipod, iphone, ipad, ios, blackberry, android). Allows a different sized video than desktop users.
mobileH264 The video asset to use by default.
mobilePosterImage The default poster image to use for all mobile devices (Android is different, see androidPosterImage below)
androidPosterImage Android phones do not currently overlay a play button on top of the video and require a slightly different implementation, for that reason, we allow a separate image for android phones with a play button in the poster image itself.
desktopVideoObject The video object that specifies the size of the video for desktop users.
desktopH264 The default h264 video for desktop users.
desktopAdditionalVideos Some browsers support different video formats. You can add additional ones and browsers will process from top-to-bottom until a compatible video is found.
desktopFlashObject The flash object to embed for the flash fallback.
desktopPosterImage The desktop poster image and fallback image in case a incompatible browser without flash is found.
*/To initialize the library, there are two implementation options:
<head> <!-- You MUST include this file. --> <script type="text/javascript" src="js/html5.js"></script> <!-- Optional file to include if you are using flash as the default and HTML5 as a fallback. --> <script src="AC_OETags.js" language="javascript" type="text/javascript"></script> <script type="text/javascript">
function init() { var video = new HTML5Video(); video.init({ outputElementId:'container', useFlashFirst:false, mobileVideoObject: new HTML5VideoObject(480,192, {"autobuffer":"autobuffer","controls":"controls"}), mobileH264: new HTML5VideoAsset("telematics_mobile.mp4","video/mp4"), mobilePosterImage: new HTML5VideoImage("telematics_mobile.jpg", 480, 192, "telematics", "No video playback capabilities."), androidPosterImage: new HTML5VideoImage("telematics_mobile_play.jpg", 480, 192), desktopVideoObject: new HTML5VideoObject(980, 390, {"autobuffer":"autobuffer","controls":"controls"}), desktopH264: new HTML5VideoAsset("telematics_desktop.mp4","video/mp4"), desktopAdditionalVideos: [new HTML5VideoAsset("telematics_desktop.ogv","video/ogg"), new HTML5VideoAsset("telematics_desktop.webm","video/webm")], desktopFlashObject: new HTML5VideoFlashObject("player.swf", 980, 414, {"allowFullScreen":"true", "flashvars":"file=telematics_desktop.flv&image=telematics_desktop.jpg"}), desktopPosterImage: new HTML5VideoImage("telematics_desktop.jpg", 980, 390, "telematics", "No video playback capabilities.") }); video.detect(); }
</script> </head> <body onload="init()"> <div id="container"></div> </body>
<html> <head> <!-- You MUST include this file. --> <script type="text/javascript" src="js/html5.js"></script> <!-- Optional file to include if you are using flash as the default and HTML5 as a fallback. --> <script src="AC_OETags.js" language="javascript" type="text/javascript"></script> </head> <body> <div id="container2" style="margin-top:30px;"> <script type="text/javascript">
var video = new HTML5Video(); video.init({ useFlashFirst:false, mobileVideoObject: new HTML5VideoObject(480,192, {"autobuffer":"autobuffer","controls":"controls"}), mobileH264: new HTML5VideoAsset("telematics_mobile.mp4","video/mp4"), mobilePosterImage: new HTML5VideoImage("telematics_mobile.jpg", 480, 192, "telematics", "No video playback capabilities."), androidPosterImage: new HTML5VideoImage("telematics_mobile_play.jpg", 480, 192), desktopVideoObject: new HTML5VideoObject(980, 390, {"autobuffer":"autobuffer","controls":"controls"}), desktopH264: new HTML5VideoAsset("telematics_desktop.mp4","video/mp4"), desktopAdditionalVideos: [new HTML5VideoAsset("telematics_desktop.ogv","video/ogg"), new HTML5VideoAsset("telematics_desktop.webm","video/webm")], desktopFlashObject: new HTML5VideoFlashObject("player.swf", 980, 414, {"allowFullScreen":"true", "flashvars":"file=telematics_desktop.flv&image=telematics_desktop.jpg"}), desktopPosterImage: new HTML5VideoImage("telematics_desktop.jpg", 980, 390, "telematics", "No video playback capabilities.") }); video.detect();
</script> </div> </body> </html>
Flash with HTML5 fallback (inline implementation)
HTML5 with Flash fallback ( <head> implementation)
Two videos on one page example: one using <head> implementation, one using the inline implementation
Javascript library file
Javascript library with example HTML source code.
Entire package with examples and test videos
Michael: Whoa Whoa Whoa… If there’s gunna be any glory stealing going on here, I’m not going to miss out. That’s right; I’m cutting in on Norm’s post and taking back some thunder.
Leveraging his newly minted JavaScript library, I have created a WordPress plugin to simplify things for those the more bloggily inclined. Simply install the plugin, use the following short codes, paste in the main parameters from the library function, and the plugin will do the rest. There is also an admin panel with documentation. Enjoy!
[FlasHTML5] useFlashFirst:false, mobileVideoObject: new HTML5VideoObject(480,192, {"autobuffer":"autobuffer","controls":"controls"}), mobileH264: new HTML5VideoAsset("http://labs.byhook.com/html5video/telematics_mobile.mp4","video/mp4"), mobilePosterImage: new HTML5VideoImage("http://labs.byhook.com/html5video/telematics_mobile.jpg", 480, 192, "telematics", "No video playback capabilities."), androidPosterImage: new HTML5VideoImage("http://labs.byhook.com/html5video/telematics_mobile_play.jpg", 480, 192), desktopVideoObject: new HTML5VideoObject(980, 390, {"autobuffer":"autobuffer","controls":"controls"}), desktopH264: new HTML5VideoAsset("http://labs.byhook.com/html5video/telematics_desktop.mp4","video/mp4"), desktopAdditionalVideos: [new HTML5VideoAsset("http://labs.byhook.com/html5video/telematics_desktop.ogv","video/ogg"), new HTML5VideoAsset("http://labs.byhook.com/html5video/telematics_desktop.webm","video/webm")], desktopFlashObject: new HTML5VideoFlashObject("http://labs.byhook.com/html5video/player.swf", 980, 414, {"allowFullScreen":"true", "flashvars":"file=http://labs.byhook.com/html5video/telematics_desktop.flv&image=http://labs.byhook.com/html5video/telematics_desktop.jpg"}), desktopPosterImage: new HTML5VideoImage("http://labs.byhook.com/html5video/telematics_desktop.jpg", 980, 390, "telematics", "No video playback capabilities.") [/FlasHTML5]
I like your blog specialization.This is one of the nice post.Thanks for your support .Good.
The article is wonderful, thanks for sharing it .
XZKKNEDYZMSHX
Welcome to Oakley Sunglasses Hut to buy cool and cheap oakleys sunglasses.
To create the great dissertation layout could be a synonym of a cemetery for some people. But there’re some other to preclude the fiasco. Thus, we would recommend to take the assistance of the dissertation service, when people are willing their story just about this post be properly composed.
This is one of the simple and good post.I like your blog details.This is one of the decent post.Try to get more this kind of collection.
Wow! This information was truly valuable to me. Ill be coming back to your blog.
Thank you for your analysis and sharing, from your article I learned more.
thank you for sharing.
thanks for sharing it and please keep doing this good job .
After reading, I learned a lot. This is a good article.caiyifang/comment201201
Thank you for sharing, this information is useful to me. good quality
Welcome to our store online: http://www.cheapjerseys-sale.com.
Cheap NFL Jerseys, NHL Jerseys, MLB Jerseys, Cheap Jerseys Sale from China, off 68%,All name and number are sewn on!
Nice post! , thanks the admin give the userful article! come on to my store have a look! I very like.
Welcome to our store online: http://www.cheapshoes-handbags.us We selling all kind of Cheap Nike Shoes, Wholesale Jordan Shoes, Cheap LV handbags,Discount Handbags,high quality, low price!
Such as, any MLB jerseys are found in these web-sites. Every theme regarding MLB shirt in your colorings you desire could access inside the web-site. Many of the MLB jerseys really are to your most current common styles. Men and women its possible miserable regarding is unable to have got a spectacular symbol of smaller little league over the hat, however , if you ever logon all the National football league jersey inexpensive, you will not ever imagined this way.
discount nike air max foreclosed homes, cleaning up after and removing all the possessions left behind by
Would you mind taking a moment of your time to help us out with a quick eval? Compensation is provided to the fastest who can help us. We left the link in the proper field, thankyou
Wind, blown crystal snowflake Solitude, tods shoes uk,tods shoes uk bleak memory, because you and warm. Merry Christmas.
replica watches
Pretty! This was a really wonderful post. Thank you for your provided information.
Nice one! Never thought of it. I used to add on delicious, but your idea is more better.
Although a pioneer in the first round out of the cut, but lost 2-4 in the Western semifinals in Seattle, stop in front of the conference finals. At the same time, Olajuwon began to grow as the top center, Sampson injury but played only 43 games. Olajuwon both ends of the court to become a leader, averaged 24.3 points, 11.4 rebounds and 3.39 blocked shots, and get him a team of three consecutive seats in the nation’s first.