jplayerview.lzx
<library>
<class name="html5mediaview">
<doc>
<tag name="shortdesc"><text>Abstract base class to support HTML5 video and audio playback.</text></tag>
<text>
<p>See <sgmltag class="element" role="LzView"><html5videoview></sgmltag> and <sgmltag class="element" role="LzView"><html5audioview></sgmltag></p>
</text>
</doc>
<attribute name="__media" value="null
"/>
<attribute name="__mdiv" value="null
"/>
<attribute name="__jqid" value="null
"/>
<event name="onabort"/>
<event name="oncanplay"/>
<event name="oncanplaythrough"/>
<event name="onemptied"/>
<event name="onended"/>
<event name="onerror"/>
<event name="onloadeddata"/>
<event name="onloadedmetadata"/>
<event name="onloadstart"/>
<event name="onpause"/>
<event name="onplay"/>
<event name="onplaying"/>
<event name="onprogress"/>
<event name="onratechange"/>
<event name="onseeked"/>
<event name="onseeking"/>
<event name="onstalled"/>
<event name="onsuspend"/>
<event name="onresize"/>
<event name="ontimeupdate"/>
<event name="onvolumechange"/>
<event name="onwaiting"/>
<event name="onreadystatechange"/>
<attribute name="ready" type="boolean" value="false
"/>
<attribute name="autobuffer" type="boolean" value="true
"/>
<setter name="autobuffer" args="val">
Debug.warn("autobuffer not yet implemented");
</setter>
<attribute name="autoplay" type="boolean" value="false
"/>
<attribute name="buffered"/>
<attribute name="controls" type="boolean" value="true
"/>
<setter name="controls" args="val">
this.controls = val;
var media = this.findMediaElement('video');
if (media != null) {
media.controls = val;
}
if (this.oncontrols) this.oncontrols.sendEvent(val);
</setter>
<method name="getCurrentSrc"> return this.__media.currentSrc; </method>
<attribute name="currentTime" type="number" value="0
"/>
<event name="oncurrentTime"/>
<setter name="currentTime" args="val">
if (this.__media != null) {
this.__media.jPlayer('play', val);
}
this.currentTime = val;
this.oncurrentTime.sendEvent(val);
this.ontimeupdate.sendEvent(val);
</setter>
<attribute name="defaultPlaybackRate" type="number" value="1.0
"/>
<attribute name="duration" type="number" value="0
"/>
<event name="onduration"/>
<attribute name="ended" type="boolean"/>
<attribute name="end" type="number"/>
<attribute name="error"/>
<attribute name="loop" type="boolean"/>
<attribute name="muted" type="boolean"/>
<setter name="muted" args="val">
this.muted = val;
if (this.__media) {
this.__media.jPlayer(val ? "mute" : "unmute");
} else {
Debug.error("trying to set muted to ", muted, "but __media is null");
}
if (this.onmuted) { this.onmuted.sendEvent(val); }
</setter>
<attribute name="networkState"/>
<attribute name="paused"/>
<attribute name="playing"/>
<attribute name="playbackRate" type="number" value="1.0
"/>
<attribute name="played"/>
<attribute name="readyState"/>
<attribute name="HAVE_NOTHING" allocation="class" value="0
"/>
<attribute name="HAVE_METADATA" allocation="class" value="1
"/>
<attribute name="HAVE_CURRENT_DATA" allocation="class" value="2
"/>
<attribute name="HAVE_FUTURE_DATA" allocation="class" value="3
"/>
<attribute name="HAVE_ENOUGH_DATA" allocation="class" value="4
"/>
<method name="seekable">
return null;
</method>
<method name="seeking">
return false;
</method>
<attribute name="src" type="string"/>
<setter name="src" args="surl">
Debug.info(this, "set src", surl);
this.removeSources();
this.addSource(surl);
if (this.onsrc) { this.onsrc.sendEvent(surl); }
</setter>
<method name="stringEndsWith" args="s1, s2">
var ind = s1.lastIndexOf(s2);
return ((ind != -1) && (ind == (s1.length - s2.length)));
</method>
<attribute name="_sources" value="null
"/>
<method name="addSource" args="src:String,encoding:String=null">
if (this._sources == null) {
this._sources = {};
}
var obj = this._sources;
var url = makeAbsoluteURL(src).toString();
if (encoding != null) {
obj[encoding] = url;
} else if (this.stringEndsWith(url, ".mov") || this.stringEndsWith(url, ".m4v") || this.stringEndsWith(url, ".mp4")) {
obj['m4v'] = url;
} else if (this.stringEndsWith(url, ".ogv")) {
obj['ogv'] = url;
} else if (this.stringEndsWith(url, ".mp3")) {
obj['mp3'] = url;
} else {
Debug.error("set src could not guess encoding type from url "+url);
}
this.src = url;
if (this.__media) {
this.__media.jPlayer("setMedia", obj);
}
if (this.onsrc) { this.onsrc.sendEvent(src); }
</method>
<method name="makeAbsoluteURL" args="target_url">
var loadurl = lz.Browser.getLoadURLAsLzURL();
loadurl.query = null;
loadurl.file = null;
var purl = new lz.URL(target_url);
if (purl.port == null && purl.host != null) { loadurl.port = null;}
var url = LzURL.merge(purl, loadurl);
if (purl.host == null) {
url.path = loadurl.path + purl.path;
}
return url;
</method>
<method name="removeSources" args="">
this._sources = null;
if (this.__media) {
this.__media.jPlayer("clearMedia");
}
</method>
<attribute name="startTime"/>
<attribute name="volume" type="number"/>
<setter name="volume" args="val">
this.volume = val;
if (this.__media) {
this.__media.jPlayer("volume", val);
}
if (this.onvolumechange) { this.onvolumechange.sendEvent(val); }
if (this.onvolume) { this.onvolume.sendEvent(val); }
</setter>
<method name="_addlisteners">
/* add all event listeners for HTML5 media element events */
var media = this.__media;
var self = this;
media.bind($.jPlayer.event.playing, function(event) { // Add a listener to report the time play began
self.currentTime = event.jPlayer.status.currentTime;
self.ended = false;
self.playing = true;
self.onplaying.sendEvent(self.currentTime);
});
media.bind($.jPlayer.event.play, function(event) { // Add a listener to report the time play began
self.currentTime = event.jPlayer.status.currentTime;
self.playing = true;
self.onplay.sendEvent(self.currentTime);
});
media.bind($.jPlayer.event.pause, function(event) { // Add a listener to report the time play began
self.currentTime = event.jPlayer.status.currentTime;
self.paused = true;
self.onpause.sendEvent(self.currentTime);
});
media.bind($.jPlayer.event.ended, function(event) {
self.ended = true;
self.onended.sendEvent(true);
});
media.bind($.jPlayer.event.timeupdate, function(event) { // Add a listener to report the current time of playhead
//Debug.info("timeupdate", self, 'time', event.jPlayer.status.currentTime, 'duration', event.jPlayer.status.duration);
self.currentTime = event.jPlayer.status.currentTime;
// Some browsers do not seem to ever get durationchange
// events, so we grab the duration from timeupdate events
// here
self.setAttribute('duration', event.jPlayer.status.duration);
if (self.oncurrentTime) { self.oncurrentTime.sendEvent(self.currentTime); }
if (self.ontimeupdate) { self.ontimeupdate.sendEvent(self.currentTime); }
});
media.bind($.jPlayer.event.suspend, function(event) {
self.onsuspend.sendEvent();
});
media.bind($.jPlayer.event.durationchange, function(event) { // Add a listener to a duration update
self.setAttribute('duration', event.jPlayer.status.duration);
});
media.bind($.jPlayer.event.canplay, function(event) {
self.oncanplay.sendEvent();
});
media.bind($.jPlayer.event.canplaythrough, function(event) {
self.oncanplaythrough.sendEvent();
});
media.bind($.jPlayer.event.seeking, function(event) {
self.onseeking.sendEvent();
});
media.bind($.jPlayer.event.seeked, function(event) {
self.onseeked.sendEvent();
});
media.bind($.jPlayer.event.loadeddata, function(event) {
self.onloadeddata.sendEvent();
});
media.bind($.jPlayer.event.loadedmetadata, function(event) {
self.onloadedmetadata.sendEvent();
});
media.bind($.jPlayer.event.stalled, function(event) {
self.onstalled.sendEvent();
});
media.bind($.jPlayer.event.waiting, function(event) {
self.onwaiting.sendEvent();
});
media.bind($.jPlayer.event.ratechange, function(event) {
self.onratechange.sendEvent();
});
media.bind($.jPlayer.event.abort, function(event) {
self.onabort.sendEvent();
});
media.bind($.jPlayer.event.emptied, function(event) {
self.onemptied.sendEvent();
});
media.bind($.jPlayer.event.progress, function(event) {
self.onprogress.sendEvent(event.jPlayer.status.currentPercentAbsolute);
});
media.bind($.jPlayer.event.resize, function(event) {
self.onresize.sendEvent([event.jPlayer.status.width, event.jPlayer.status.height]);
});
media.bind($.jPlayer.event.volumechange, function(event) {
self.volume = event.jPlayer.status.volume;
if (self.onvolume) { self.onvolume.sendEvent(self.volume); }
});
media.bind($.jPlayer.event.error, function(event) { //
Debug.error ("jplayerview error event: type = " + event.jPlayer.error.type + "\n" +
event.jPlayer.error.message+"\n" + event.jPlayer.error.hint );
self.onerror.sendEvent(event.jPlayer.error.type);
});
/* $.jPlayer.event.ready * †
$.jPlayer.event.resize * †
$.jPlayer.event.error * ‡
$.jPlayer.event.warning * †
$.jPlayer.event.loadstart *
$.jPlayer.event.progress *
$.jPlayer.event.suspend
$.jPlayer.event.abort
$.jPlayer.event.emptied
$.jPlayer.event.stalled
$.jPlayer.event.play *
$.jPlayer.event.pause *
$.jPlayer.event.loadedmetadata
$.jPlayer.event.loadeddata
$.jPlayer.event.waiting
$.jPlayer.event.playing
$.jPlayer.event.canplay
$.jPlayer.event.canplaythrough
$.jPlayer.event.seeking *
$.jPlayer.event.seeked *
$.jPlayer.event.timeupdate *
$.jPlayer.event.ended *
$.jPlayer.event.ratechange
$.jPlayer.event.durationchange
$.jPlayer.event.volumechange *
eventHandler(event)
event : Object: Standard jQuery $.Event() properties.
event.jPlayer : Object : The jPlayer information object.
event.jPlayer.error : Object
event.jPlayer.error.type : String : The error event code
event.jPlayer.error.context : String : The cause of the error
event.jPlayer.error.message : String : Message describing the error
event.jPlayer.error.hint : String : A suggestion on how to fix the error
event.jPlayer.flash : Object : Info about the Flash solution
event.jPlayer.html : Object : Info about the HTML solution
event.jPlayer.status : Object
event.jPlayer.status.src : String : The URL being used by jPlayer.
event.jPlayer.status.file : Object : Pointer to the media object used in setMedia.
event.jPlayer.status.seekPercent : Number : Percent seekable
event.jPlayer.status.currentPercentRelative : Number : Current time as a percent of seekPercent
event.jPlayer.status.currentPercentAbsolute : Number : Current time as a percent of duration
event.jPlayer.status.currentTime : Number : The current time in seconds
event.jPlayer.status.duration : Number : The duration of the media
event.jPlayer.status.volume : Number
event.jPlayer.status.muted : Boolean
event.jPlayer.status.srcSet : Boolean
event.jPlayer.status.paused : Boolean
event.jPlayer.status.waitForPlay : Boolean
event.jPlayer.status.waitForLoad : Boolean
event.jPlayer.status.video : Boolean
event.jPlayer.status.width : String : The CSS style width of jPlayer.
event.jPlayer.status.height : String : The CSS style height of jPlayer.
event.jPlayer.version : Object
event.jPlayer.version.script : String : jPlayer's JavaScript version
event.jPlayer.version.flash : String : jPlayer's Flash version, or "unknown" if Flash is not being used
event.jPlayer.version.needFlash : String : The Flash version compatiable with the JavaScript
event.jPlayer.warning : Object
event.jPlayer.warning.type : String : The warning event code
event.jPlayer.warning.context : String : The cause of the warning
event.jPlayer.warning.message : String : Message describing the warning
event.jPlayer.warning.hint : String : A suggestion on how to fix the warning
*/
</method>
<setter name="height" args="h">
super.setAttribute ('height', h);
if (this.__mdiv) {
this.__mdiv.height = h;
this.__mdiv.style.height = h + "px";
}
</setter>
<setter name="width" args="w">
super.setAttribute ('width', w);
if (this.__mdiv) {
this.__mdiv.width = w;
this.__mdiv.style.width = w + "px";
}
</setter>
<method name="canPlayType" args="mtype">
return this.__media.canPlayType(mtype);
</method>
<method name="load">
this.__media.jPlayer("load");
</method>
<method name="pause" args="pt=null">
this.__media.jPlayer("pause", pt);
</method>
<method name="play" args="pt=null">
this.__media.jPlayer("play",pt);
</method>
<handler name="oninit">
this.makePlayer();
</handler>
<event name="onready"/>
<handler name="onready">
//Debug.info(this, "onready autoplay=",this.autoplay);
if (this.__media && this._sources != null) {
this.__media.jPlayer("setMedia", this._sources);
}
var mediaElt = this.findMediaElement(this.__kind);
if (mediaElt != null) {
mediaElt.controls = this.controls;
}
if (this.autoplay) {
this.play();
}
</handler>
<attribute name="__kind"/>
</class>
<class name="html5videoview" extends="html5mediaview">
<doc>
<text>
<p><tagname>html5videoview</tagname> allows applications to play video from HTTP servers.</p>
<example><programlisting class="code">
<canvas>
<html5videoview src="http://www.archive.org/download/SoundieF/SoundieF_512kb.mp4" autoplay="true" width="320" height="240"/>
</canvas>
</programlisting></example>
</text>
</doc>
<method name="makePlayer">
this.__kind = 'video';
//Debug.info("makePlayer");
var self = this;
var vid = document.createElement('div');
vid.style.width = "640"
vid.style.height = "360";
this.__mdiv = vid;
var pid = this.__LZUID;
vid.id = pid;
// This is how we refer to the jplayer via jquery
this.__jqid = "#" + pid;
vid.className = "jp-jplayer";
vid.style.width = LzKernelUtils.CSSDimension(this.width);
vid.style.height = LzKernelUtils.CSSDimension(this.height);
this.sprite.__LZdiv.appendChild(vid);
setTimeout(function() {
$(self.__jqid).jPlayer({
ready: function () {
//Debug.info(self , "makePlayer ready function", self.__jqid);
if (!self.ready) {
self.__media = $(self.__jqid);
self._addlisteners();
self.setAttribute('ready', true);
}
},
supplied: "m4v,mp3",
swfPath: "js"});
}, 0);
</method>
<method name="_addlisteners">
super._addlisteners();
</method>
<event name="onbeginfullscreen"/>
<event name="onendfullscreen"/>
<attribute name="poster" type="string"/>
<setter name="poster" args="val">
if (this.__media) {
}
</setter>
<method name="getVideoWidth">
Debug.warn(self, "getVideoWidth NYI");
return this.width;
</method>
<method name="getVideoHeight">
Debug.warn(self, "getVideoHeight NYI");
return this.height;
</method>
<method name="getDisplayingFullscreen">
return this.__media.webkitDisplayingFullscreen();
</method>
<method name="getSupportsFullscreen">
return this.__media.webkitSupportsFullscreen();
</method>
<method name="enterFullscreen">
var video = this.findMediaElement('video');
video.webkitEnterFullscreen();
</method>
<method name="exitFullscreen">
var video = this.findMediaElement('video');
video.webkitExitFullscreen();
</method>
<method name="findMediaElement" args="kind">
return this.__media ? this.__media.data('jPlayer').htmlElement.video : null;
</method>
</class>
</library>