Web UI for ARGUS server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

404 lines
8.5 KiB

6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /**
  2. * Constructor
  3. */
  4. var FlashFLVPlayer = function(htmlElement)
  5. {
  6. this.version = "0.1.0";
  7. // Constants
  8. this.NETWORK_EMPTY = 0;
  9. this.NETWORK_IDLE = 1;
  10. this.NETWORK_LOADING = 2;
  11. this.NETWORK_LOADED = 3;
  12. this.NETWORK_NO_SOURCE = 4;
  13. this.HAVE_NOTHING = 0;
  14. this.HAVE_METADATA = 1;
  15. this.HAVE_CURRENT_DATA = 2;
  16. this.HAVE_FUTURE_DATA = 3;
  17. this.HAVE_ENOUGH_DATA = 4;
  18. this.MEDIA_ERR_ABORTED = 1;
  19. this.MEDIA_ERR_NETWORK = 2;
  20. this.MEDIA_ERR_DECODE = 3;
  21. this.MEDIA_ERR_SRC_NOT_SUPPORTED = 4;
  22. // Variables
  23. this.error = null;
  24. this.src = "";
  25. this.currentSrc = "";
  26. this.networkState = this.NETWORK_EMPTY;
  27. this.autobuffer = true;
  28. this.buffered = null;
  29. this.readyState = this.HAVE_NOTHING;
  30. this.seeking = false;
  31. this.currentTime = 0;
  32. this.startTime = 0;
  33. this.duration = 0;
  34. this.paused = true;
  35. this.defaultPlaybackRate = 1;
  36. this.playbackRate = 1;
  37. this.played = null;
  38. this.seekable = null;
  39. this.ended = false;
  40. this.autoplay = false;
  41. this.loop = false;
  42. this.controls = false;
  43. this.volume = 1;
  44. this.muted = false;
  45. this.width = 0;
  46. this.height = 0;
  47. this.videoWidth = 0;
  48. this.videoHeight = 0;
  49. this.poster = "";
  50. // Private variables
  51. this._flash = htmlElement;
  52. this._eventListeners = new Object();
  53. // Getters / Setters
  54. //this.__defineSetter__("currentTime", this.setCurrentTime);
  55. // Default event handlers
  56. this.addEventListener("play", this._playHandler);
  57. this.addEventListener("pause", this._pauseHandler);
  58. this.addEventListener("seeked", this._seekedHandler);
  59. this.addEventListener("loadstart", this._loadstartHandler);
  60. this.addEventListener("progress", this._progressHandler);
  61. this.addEventListener("load", this._loadHandler);
  62. this.addEventListener("durationchange", this._durationchangeHandler);
  63. this.addEventListener("volumechange", this._volumechangeHandler);
  64. this.addEventListener("timeupdate", this._timeupdateHandler);
  65. this.addEventListener("loadedmetadata", this._loadedmetadataHandler);
  66. this.addEventListener("playing", this._playingHandler);
  67. this.addEventListener("ended", this._endedHandler);
  68. this.addEventListener("canplay", this._canplayHandler);
  69. this.addEventListener("canplaythrough", this._canplaythroughHandler);
  70. this.addEventListener("error", this._errorHandler);
  71. };
  72. FlashFLVPlayer.prototype = {
  73. /**
  74. * Indicates the Javascript is ready for the Flash
  75. */
  76. isReady: function()
  77. {
  78. return true;
  79. },
  80. /**
  81. * Add event listener
  82. */
  83. addEventListener: function(type, callback)
  84. {
  85. if (!this._eventListeners[type]) {
  86. this._eventListeners[type] = new Array();
  87. }
  88. this._eventListeners[type].push(callback);
  89. },
  90. /**
  91. * Dispatch an event
  92. */
  93. dispatchEvent: function(event)
  94. {
  95. var type = event.type;
  96. // Bug: the flash continues to dispatch event after a refresh
  97. if (type != "error" && type != "play" && type != "loadstart" && this.networkState == this.NETWORK_EMPTY) {
  98. return;
  99. }
  100. // Dispatch to all listeners
  101. // Quick delegate with "apply"
  102. if (this._eventListeners[type]) {
  103. for (var i = 0; i < this._eventListeners[type].length; i++) {
  104. this._eventListeners[type][i].apply(this, [event]);
  105. }
  106. }
  107. },
  108. /**
  109. * Load and play the video
  110. */
  111. load: function()
  112. {
  113. this._flash.play();
  114. },
  115. /**
  116. * Play the video
  117. */
  118. play: function()
  119. {
  120. if( this._flash && typeof this._flash.flashPlay == "function") {
  121. this._flash.flashPlay();
  122. } else {
  123. alert("Flash not ready");
  124. }
  125. },
  126. /**
  127. * Pause
  128. */
  129. pause: function()
  130. {
  131. if( this._flash && typeof this._flash.flashPause != "undefined") {
  132. this._flash.flashPause();
  133. } else {
  134. alert("Flash not ready");
  135. }
  136. },
  137. /**
  138. * Get the currentTime
  139. *
  140. * @return The value
  141. */
  142. getCurrentTime: function()
  143. {
  144. return this.currentTime;
  145. },
  146. /**
  147. * Set the new currentTime
  148. *
  149. * @param value The new value
  150. */
  151. setCurrentTime: function(value)
  152. {
  153. this.currentTime = value;
  154. },
  155. /**
  156. * Get the volume
  157. *
  158. * @return The value
  159. */
  160. getVolume: function()
  161. {
  162. return this.volume;
  163. },
  164. /**
  165. * Set the new volume
  166. *
  167. * @param value The new value
  168. */
  169. setVolume: function(value)
  170. {
  171. this.volume = value;
  172. },
  173. /**
  174. * Set the new duration
  175. *
  176. * @param value The new value
  177. */
  178. setDuration: function(value)
  179. {
  180. this.duration = value;
  181. },
  182. /**
  183. * Set the video width
  184. *
  185. * @param value The value
  186. */
  187. setVideoWidth: function(value)
  188. {
  189. this.videoWidth = value;
  190. },
  191. /**
  192. * Set the video height
  193. *
  194. * @param value The value
  195. */
  196. setVideoHeight: function(value)
  197. {
  198. this.videoHeight = value;
  199. },
  200. /**
  201. * Set the playback rate
  202. *
  203. * @param value The value
  204. */
  205. setPlaybackRate: function(value)
  206. {
  207. this.defaultPlaybackRate = value;
  208. this.playbackRate = value;
  209. },
  210. /**
  211. * "play" event handler
  212. *
  213. * @param event The event
  214. */
  215. _playHandler: function(event)
  216. {
  217. this.paused = false;
  218. },
  219. /**
  220. * "pause" event handler
  221. *
  222. * @param event The event
  223. */
  224. _pauseHandler: function(event)
  225. {
  226. this.paused = true;
  227. },
  228. /**
  229. * "durationchange" event handler
  230. *
  231. * @param event The event
  232. */
  233. _durationchangeHandler: function(event)
  234. {
  235. },
  236. /**
  237. * "volumechange" event handler
  238. *
  239. * @param event The event
  240. */
  241. _volumechangeHandler: function(event)
  242. {
  243. },
  244. /**
  245. * "timeupdate" event handler
  246. *
  247. * @param event The event
  248. */
  249. _timeupdateHandler: function(event)
  250. {
  251. },
  252. /**
  253. * "loadedmetadata" event handler
  254. *
  255. * @param event The event
  256. */
  257. _loadedmetadataHandler: function(event)
  258. {
  259. if (this.readyState < this.HAVE_METADATA) {
  260. this.readyState = this.HAVE_METADATA;
  261. }
  262. },
  263. /**
  264. * "seeked" event handler
  265. *
  266. * @param event The event
  267. */
  268. _seekedHandler: function(event)
  269. {
  270. },
  271. /**
  272. * "playing" event handler
  273. *
  274. * @param event The event
  275. */
  276. _playingHandler: function(event)
  277. {
  278. if (this.readyState < this.HAVE_FUTURE_DATA) {
  279. this.readyState = this.HAVE_FUTURE_DATA;
  280. }
  281. this.paused = false;
  282. this.seeking = false;
  283. },
  284. /**
  285. * "ended" event handler
  286. *
  287. * @param event The event
  288. */
  289. _endedHandler: function(event)
  290. {
  291. this.ended = true;
  292. },
  293. /**
  294. * "loadstart" event handler
  295. *
  296. * @param event The event
  297. */
  298. _loadstartHandler: function(event)
  299. {
  300. this.networkState = this.NETWORK_LOADING;
  301. },
  302. /**
  303. * "progress" event handler
  304. *
  305. * @param event The event
  306. */
  307. _progressHandler: function(event)
  308. {
  309. this.networkState = this.NETWORK_LOADING;
  310. },
  311. /**
  312. * "load" event handler
  313. *
  314. * @param event The event
  315. */
  316. _loadHandler: function(event)
  317. {
  318. this.networkState = this.NETWORK_LOADED;
  319. },
  320. /**
  321. * "canplay" event handler
  322. *
  323. * @param event The event
  324. */
  325. _canplayHandler: function(event)
  326. {
  327. if (this.readyState < this.HAVE_FUTURE_DATA) {
  328. this.readyState = this.HAVE_FUTURE_DATA;
  329. }
  330. },
  331. /**
  332. * "canplaythrough" event handler
  333. *
  334. * @param event The event
  335. */
  336. _canplaythroughHandler: function(event)
  337. {
  338. if (this.readyState < this.HAVE_ENOUGH_DATA) {
  339. this.readyState = this.HAVE_ENOUGH_DATA;
  340. }
  341. },
  342. /**
  343. * "error" event handler
  344. *
  345. * @param event The event
  346. */
  347. _errorHandler: function(event)
  348. {
  349. this.error = new Object();
  350. switch (event.code) {
  351. case "no_source":
  352. this.networkState = this.NETWORK_NO_SOURCE;
  353. this.error.code = this.MEDIA_ERR_SRC_NOT_SUPPORTED;
  354. break;
  355. default:
  356. this.error.code = 0;
  357. }
  358. }
  359. };