diff -r 353b0881a0b9 -r b1c3bf6eca78 src/widgets/MashupPlayer.js --- a/src/widgets/MashupPlayer.js Tue Oct 02 18:08:05 2012 +0200 +++ b/src/widgets/MashupPlayer.js Wed Oct 24 11:08:31 2012 +0200 @@ -17,21 +17,31 @@ IriSP.Widgets.MashupPlayer.prototype.draw = function() { var _this = this, _mashup = this.media, - _pauseState = (!this.autostart && !this.autoplay), _currentMedia = null, _currentAnnotation = null, _segmentBegin, _segmentEnd, _timecode = 0, + _seeking = false, + _seekdiv, _timedelta; + _mashup.paused = (!this.autostart && !this.autoplay) + function changeCurrentAnnotation() { + if (_timecode >= _mashup.duration) { + if (!_mashup.paused) { + _mashup.paused = true; + _mashup.trigger("pause"); + } + _timecode = 0; + } var _annotation = _mashup.getAnnotationAtTime( _timecode ); if (typeof _annotation === "undefined") { if (_currentMedia) { _currentMedia.pause(); - if (!_pauseState) { - _pauseState = true; + if (!_mashup.paused) { + _mashup.paused = true; _mashup.trigger("pause"); } } @@ -65,7 +75,10 @@ if (IriSP._(_preloadedMedias).indexOf(_media.id) === -1) { _preloadedMedias.push(_media.id); _media.setCurrentTime(_a.annotation.begin.getSeconds()); - //console.log("Preloading ", _media.id, " at t=", _a.annotation.begin.getSeconds()); + _media.seeking = true; +/* + console.log("Preloading ", _media.id, " at t=", _a.annotation.begin.getSeconds()); +*/ } }); @@ -73,11 +86,18 @@ // } else { // console.log("changeCurrentAnnotation called, but segment hasn't changed"); } - - if (!_pauseState) { + + _currentMedia.setCurrentTime( _timecode + _timedelta); + _currentMedia.seeking = true; + + if (!_mashup.paused) { _currentMedia.play(); + _seeking = true; + _seekdiv.show(); } - _currentMedia.setCurrentTime( _timecode + _timedelta); +/* + console.log("Setting time of media", _currentMedia.id, "to", _timecode + _timedelta) +*/ _mashup.trigger("timeupdate", new IriSP.Model.Time(_timecode)); } @@ -100,7 +120,6 @@ IriSP._(_mashup.medias).each(function(_media, _key) { var _el = IriSP.jQuery('
'); _el.css({ - position: "absolute", top: (_this.split_screen ? _height * Math.floor(_key / _grid) : 0), left: (_this.split_screen ? _width * (_key % _grid) : 0), height: _height, @@ -134,33 +153,51 @@ _allLoaded = _allLoaded && _mashup.medias[_i].loadedMetadata; } if (_allLoaded) { + _seekdiv.fadeOut(); changeCurrentAnnotation(); _mashup.trigger("loadedmetadata"); } }); _media.on("timeupdate", function(_time) { - if (!_pauseState && _media === _currentMedia) { -// var _status = "Timeupdate from " + _media.id + " at time " + _time; + if (!_mashup.paused && _media === _currentMedia && !_media.seeking) { +/* + var _status = "Timeupdate from " + _media.id + " at time " + _time; +*/ if ( _time < _segmentEnd ) { if ( _time >= _segmentBegin ) { _timecode = _time - _timedelta; -// _status += " within segment"; +/* + _status += " within segment"; +*/ } else { _timecode = _segmentBegin - _timedelta; _media.setCurrentTime(_segmentBegin); -// _status += " before segment"; +/* + _status += " before segment"; +*/ } } else { _timecode = _segmentEnd - _timedelta; _media.pause(); changeCurrentAnnotation(); -// _status += " after segment"; +/* + _status += " after segment"; +*/ } -// _status += " (" + _this.segmentBegin + " to " + _this.segmentEnd + ")" + ", translated to " + _this.timecode; -// console.log(_status); +/* + _status += " (" + _segmentBegin + " to " + _segmentEnd + ")" + ", translated to " + _timecode; + console.log(_status); +*/ _mashup.trigger("timeupdate", new IriSP.Model.Time(_timecode)); } }); + _media.on("seeked", function() { + _media.seeking = false; + if (_media === _currentMedia && _seeking) { + _seeking = false; + _seekdiv.hide(); + } + }) _media.on("play", function() { if (_media === _currentMedia) { _mashup.trigger("play"); @@ -171,49 +208,49 @@ _mashup.trigger("pause"); } }); + _media.on("volumechange", function() { + _mashup.muted = _media.muted; + _mashup.volume = _media.volume; + _mashup.trigger("volumechange"); + }); }); - - _mashup.getCurrentTime = function() { - return new IriSP.Model.Time(_timecode); - } - _mashup.getVolume = function() { - return ( _currentMedia ? _currentMedia.getVolume() : .5 ); - } - _mashup.getPaused = function() { - return _pauseState; - } - _mashup.getMuted = function() { - return ( _currentMedia ? _currentMedia.getMuted() : false ); - } - _mashup.setCurrentTime = function(_milliseconds) { + + _seekdiv = IriSP.jQuery('
'); + + this.$.append(_seekdiv); + + // Binding functions to Popcorn + + _mashup.on("setcurrenttime", function(_milliseconds) { _timecode = _milliseconds; changeCurrentAnnotation(); - } - _mashup.setVolume = function(_vol) { + }); + + _mashup.on("setvolume", function(_vol) { for (var _i = 0; _i < _mashup.medias.length; _i++) { _mashup.medias[_i].setVolume(_vol); } - } - _mashup.mute = function() { - for (var _i = 0; _i < _mashup.medias.length; _i++) { - _mashup.medias[_i].mute(); - } - } - _mashup.unmute = function() { + _mashup.volume = _vol; + }); + + _mashup.on("setmuted", function(_muted) { for (var _i = 0; _i < _mashup.medias.length; _i++) { - _mashup.medias[_i].unmute(); + _mashup.medias[_i].setMuted(_muted); } - } - _mashup.play = function() { - _pauseState = false; + _mashup.muted = _muted; + }); + + _mashup.on("setplay", function() { + _mashup.paused = false; changeCurrentAnnotation(); - } - _mashup.pause = function() { - _pauseState = true; + }); + + _mashup.on("setpause", function() { + _mashup.paused = true; if (_currentMedia) { _currentMedia.pause(); } - } + }); _mashup.on("loadedmetadata", changeCurrentAnnotation);