/* Handles initializing the HTML5 Video Player */ var init = function initializeHTML5Player () { var base = H5Settings.playlist.videos[0].videoUrl; if (H5Settings.css){ var dynamicStyle=document.createElement("link"); dynamicStyle.setAttribute("rel", "stylesheet"); dynamicStyle.setAttribute("type", "text/css"); dynamicStyle.setAttribute("href","http://www.nbcnews.com/id/"+ H5Settings.css+"/14?.css"); document.getElementsByTagName("head")[0].appendChild(dynamicStyle); } /* parse from the query string whether or not to show the rest state */ //var showRestState = (H5Settings.showRestState == undefined || H5Settings.showRestState == null) ? true : H5Settings.showRestState; var showRestState = true; var pattern = "[\\?&]showRestState=([^&#]*)"; var regex = new RegExp( pattern ); var results = regex.exec( document.location.href ); // if( results != null ) // showRestState = results[1]; /* initialize ui objects for dependency injection */ var buttons = { "fastForward" : $("#fastForwardButton"), "mute" : $("#muteButton"), "pause" : $("#pauseButton"), "play" : $("#playButton"), "restState" : $("#restStateButton"), "rewind" : $("#reverseButton"), "stop" : $("#stopButton"), "wifi" : $("#wifiBitrateButton"), "3G" : $("#threeGBitrateButton") }; var html5Video = $("#html5Video"); var playerControls = $("#html5PlayerControls"); var playlist = $("#html5Playlist"); var playlistSourceLogo = $("#html5PlaylistSourceLogo"); var playlistDate = $("#html5PlaylistDate"); var playlistCaption = $("#html5PlaylistCaption"); var playlistThumbs = $("#html5PlaylistVideoThumbs"); var playlistScrollbar = $("#html5PlaylistScrollbar"); var slider = $("#html5PlayerSlider"); var bitrateChooser = $("#html5VideoBitrateChooser"); var volumeBar = $("#html5VolumeControlsVolumeBar"); var volumeControls = $("#html5VolumeControls"); var adSpace = $("#html5AdSpace"); var viewportSplash = $("#html5ViewportSplash"); var waitImage = "http://media1.s-nbcnews.com/i/MSNBC/Components/Video/_Player/configurations/No%20Modify/HTML5/img/NBCNEWSLoad.gif"; var errorImage = "http://media1.s-nbcnews.com/i/MSNBC/Components/Video/_Player/configurations/No%20Modify/HTML5/img/NBCNewsfail.gif"; //var errorImage = "http://media1.s-nbcnews.com/i/MSNBC/Components/Video/_Player/configurations/No%20Modify/HTML5/img/fail_out.gif"; var viewport = $("#html5Viewport"); var timeDisplay = $("#timeDisplay"); /* set some initial states */ buttons.restState.show(); /* TEMPORARY UNTIL WE KNOW WHAT WE'RE Doing WITH ADS */ // adSpace.hide(); /* create controllers */ var sliderController = new Slider( slider ); var controlsController = new Controls( playerControls, viewport, buttons, showRestState, timeDisplay, H5Settings.bitrate); var volumeController = new Volume( volumeBar, buttons, playlist, volumeControls ); var videoController = new VideoController( html5Video, buttons, volumeController, viewportSplash, waitImage, errorImage, showRestState, bitrateChooser, H5Settings.bitrate ); var playlistController = new PlaylistController( playlist, playlistSourceLogo, playlistDate, playlistCaption, playlistThumbs, playlistScrollbar, videoController); /* Added Controller Event Subscriptions */ videoController.addStateChangedHandler( function(state) { controlsController.handleStateChanged(state) } ); videoController.addStateChangedHandler( function(state) { sliderController.handleStateChanged(state) } ); videoController.addStateChangedHandler( function(state) { playlistController.handleStateChanged(state) } ); sliderController.addPlayPercentChangedHandler( function(percent) { videoController.handlePlayPercentChanged(percent) } ); volumeController.addVolumeChangedHandler( function(value) { videoController.handleVolumeChanged(value) } ); videoController.addTimeUpdateHandler( sliderController ); videoController.addTimeUpdateHandler(controlsController); videoController.addTimeUpdateHandler(playlistController); videoController.addBitrateChangedHandler( function(bitrate) { controlsController.handleBitrateChanged(bitrate) } ); /* Wire Up Slider Event Subscriptions */ slider.bind("click", function( event ) { var playlistWidth = parseInt(playlist.css("width")); var newEvent = { pageX : (event.pageX - playlistWidth + 15), pageY : event.pageY }; sliderController.click( newEvent ); return false; }); var touchHandler = function(event) { if($(event.target).attr("id") != undefined) { var isPlaylist = ($(event.target).attr("id").substr(0,13) == "html5Playlist") ? true : false; if(isPlaylist) { playlistController.touchHandler(event); } } }; /* Wire up touch event subscriptions */ document.addEventListener("touchstart", touchHandler, false); document.addEventListener("touchmove", touchHandler, false); document.addEventListener("touchend", touchHandler, false); document.addEventListener("touchcancel", touchHandler, false); /* remove the initialization screen and show the player */ $("#html5PlayerLoadingScreen").fadeOut(); $("#html5Player").fadeIn(); /* Load the video */ playlistController.ApplicationInitialized(); }; function loadHTML5VideoPlayer() { /* Add the HTML5 Player Initialization Handler */ H5Settings.addLoadedHandler(init); /* Load the Video Metadata */ H5Settings.loadVideo(); };