Note: As of late 2011, there’s a better way to do this now.
Code to insert a player inside a div (named videoframe in this case). This will present either an instance of JW Player version 5 (default), JW Player version 4 for PlayStation (which do not have Flash 10), an HTML5 video element in the case of iPhone/iPad devices, and a graphic (that looks like JW Player for a consistent UX) hyperlinked to an RTSP feed for Android/BlackBerry/WebOS devices or an MMS feed for IE Mobile devices. David Walsh also has a post about how to do it with PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | <div id= "videoframe" ></div> <SCRIPT type= "text/javascript" > // Browser-aware video player for JW Player and Wowza // V0.2 - June 2, 2010 // (c)2010 Ian Beyer // Released under the GPL var agent=navigator.userAgent.toLowerCase(); var is_iphone = (agent.indexOf( 'iphone' )!=-1); var is_ipad = (agent.indexOf( 'ipad' )!=-1); var is_playstation = (agent.indexOf( 'playstation' )!=-1); var is_safari = (agent.indexOf( 'safari' )!=-1); var is_iemobile = (agent.indexOf( 'iemobile' )!=-1); var is_blackberry = (agent.indexOf( 'blackberry' )!=-1); var is_android = (agent.indexOf( 'android' )!=-1); var is_webos = (agent.indexOf( 'webos' )!=-1); if (is_iphone) { html5Player();} else if (is_ipad) { html5Player(); } else if (is_android) { rtspPlayer(); } else if (is_webos) { rtspPlayer(); } else if (is_blackberry) { rtspPlayer(); } else if (is_iemobile) { windowsPlayer(); } else if (is_playstation) { oldJWPlayer(); } else { newJWPlayer(); } function html5Player() { var player=document.getElementById( "player" ) player.innerHTML= '<VIDEO ' + 'SRC="http://wowza2:1935/live/stream/playlist.m3u8" ' + 'HEIGHT="480" ' + 'WIDTH="640" ' + 'poster="poster.png" ' + 'title="Live Stream">' + '</video>' ; } function rtspPlayer() { var player=document.getElementById( "player" ) player.innerHTML= '<A HREF="rtsp://wowza2:1935/live/stream">' + '<IMG SRC="player-fake.png" ' + 'ALT="Start Mobile Video" ' + 'BORDER="0" ' + 'HEIGHT="480" ' + 'WIDTH="640">' + '</A>' ; } function windowsPlayer() { var player=document.getElementById( "player" ) player.innerHTML= '<A HREF="mms://windows/pubpoint">' + '<IMG SRC="player-fake.png" ' + 'ALT="Start Windows Mobile Video" ' + 'BORDER="0" ' + 'HEIGHT="480" ' + 'WIDTH="640">' + '</A>' ; } function oldJWPlayer() { var so = new SWFObject( 'player-45.swf' , 'mpl' , '640' , '480' , '8' ); so.addParam( 'allowfullscreen' , 'true' ); so.addParam( 'allowscriptaccess' , 'always' ); so.addParam( 'wmode' , 'opaque' ); so.addVariable( 'autostart' , 'false' ); so.addVariable( 'type' , 'rtmp' ); so.addVariable( 'streamer' , 'rtmp://wowza-origin:1935/redirect' ); so.addVariable( 'file' , 'stream' ); so.addVariable( 'controlbar' , 'over' ); so.addVariable( 'dock' , 'true' ); so.addVariable( 'image' , 'poster.png' ); so.write( 'player' ); } function newJWPlayer() { var so = new SWFObject( 'player-5.swf' , 'mpl' , '640' , '480' , '10' ); so.addParam( 'allowfullscreen' , 'true' ); so.addParam( 'allowscriptaccess' , 'always' ); so.addParam( 'wmode' , 'opaque' ); so.addVariable( 'autostart' , 'false' ); so.addVariable( 'type' , 'rtmp' ); so.addVariable( 'streamer' , 'rtmp://wowza-origin:1935/redirect' ); so.addVariable( 'file' , 'stream' ); so.addVariable( 'controlbar' , 'over' ); so.addVariable( 'dock' , 'true' ); so.addVariable( 'image' , 'poster.png' ); so.write( 'player' ); } </SCRIPT> |