Source: tools/interfaces.js

  1. /**
  2. * @file This file contains interface definitions.
  3. * The interface definitions are purely for documentation and
  4. * should not be loaded / executed / or used in any way other
  5. * than for reference purposes.
  6. */
  7. /**
  8. * The Audio abstraction that is returned by {@link mmir.MediaManager#getURLAsAudio}.
  9. *
  10. * <p>
  11. * NOTE: when an audio object is not used anymore, its {@link #release} method should
  12. * be called.
  13. *
  14. * <p>
  15. *
  16. * @interface
  17. * @name IAudio
  18. * @memberOf mmir.env.media
  19. * @public
  20. */
  21. var IAudio = {
  22. /**
  23. * The constructor.
  24. *
  25. * <p>
  26. * NOTE that audio objects are created with a factory,
  27. * e.g. via {@link mmir.MediaManager#getURLAsAudio}.
  28. *
  29. * @param {String} url
  30. * the URL for the audio file
  31. * @param {Function} [onPlayedCallback] OPTIONAL
  32. * callback that is triggered when audio did play and has ended
  33. * @param {Function} [failureCallBack] OPTIONAL
  34. * callback that is triggered when an error occurs (usually during initialization)<br>
  35. * NOTE: this argument is positional (i.e. onPlayedCallback must be specified, but may be <code>null</code>)
  36. * @param {Function} [onLoadedCallBack] OPTIONAL
  37. * callback that is triggered when audio has been initialized and is ready to be played
  38. * NOTE: this argument is positional (i.e. onPlayedCallback and failureCallBack must be specified, but may be <code>null</code>)
  39. *
  40. * @protected
  41. * @function
  42. * @name _constructor
  43. * @memberOf mmir.env.media.IAudio.prototype
  44. *
  45. * @see mmir.MediaManager#getURLAsAudio
  46. *
  47. * @example
  48. * var audio = mmir.MediaManager.getURLAsAudio(url, null, null, function onReady(){
  49. * audio.play();
  50. * });
  51. */
  52. _constructor: function(url, onPlayedCallback, failureCallBack, onLoadedCallBack){},
  53. /**
  54. * Play audio.
  55. *
  56. * @returns {Boolean} <code>true</code>, if playing was started immediately.
  57. * If <code>false</code>, the Audio object may have been disabled,
  58. * or is still preparing (in which case it is auto-started, when
  59. * preparing completes)
  60. *
  61. * @public
  62. * @name play
  63. * @function
  64. * @memberOf mmir.env.media.IAudio.prototype
  65. */
  66. play: function(){},
  67. /**
  68. * Stop playing audio.
  69. *
  70. * @returns {Boolean} <code>true</code>, if stopping was successful.
  71. *
  72. * @public
  73. * @name stop
  74. * @function
  75. * @memberOf mmir.env.media.IAudio.prototype
  76. */
  77. stop: function(){},
  78. /**
  79. * Enable audio (should only be used internally).
  80. *
  81. * @protected
  82. * @name enable
  83. * @function
  84. * @memberOf mmir.env.media.IAudio.prototype
  85. */
  86. enable: function(){},
  87. /**
  88. * Disable audio (should only be used internally).
  89. *
  90. * @protected
  91. * @name disable
  92. * @function
  93. * @memberOf mmir.env.media.IAudio.prototype
  94. */
  95. disable: function(){},
  96. /**
  97. * Release audio: should be called when the audio
  98. * file is not used any more.
  99. *
  100. * <p>
  101. * NOTE some environments - such as Android - have limited resources available.
  102. * Not releasing resources may result in not being able to instantiate new
  103. * (audio) resources.
  104. *
  105. * @public
  106. * @name release
  107. * @function
  108. * @memberOf mmir.env.media.IAudio.prototype
  109. */
  110. release: function(){},
  111. /**
  112. * Set the volume of this audio file
  113. *
  114. * @param {Number} value
  115. * the new value for the volume:
  116. * a number between [0.0, 1.0]
  117. *
  118. * @public
  119. * @name setVolume
  120. * @function
  121. * @memberOf mmir.env.media.IAudio.prototype
  122. */
  123. setVolume: function(value){},
  124. /**
  125. * Get the duration of the audio file
  126. *
  127. * @returns {Number} the duration in MS (or <code>-1</code> if unknown)
  128. *
  129. * @public
  130. * @name getDuration
  131. * @function
  132. * @memberOf mmir.env.media.IAudio.prototype
  133. */
  134. getDuration: function(){},
  135. /**
  136. * Check if audio is currently paused.
  137. *
  138. * <p>
  139. * NOTE: the state "paused" is a different status than state "stopped".
  140. *
  141. * @returns {Boolean} <code>true</code> if paused, <code>false</code> otherwise
  142. *
  143. * @public
  144. * @name isPaused
  145. * @function
  146. * @memberOf mmir.env.media.IAudio.prototype
  147. */
  148. isPaused: function(){},
  149. /**
  150. * Check if audio is currently enabled
  151. *
  152. * @returns {Boolean} <code>true</code> if enabled
  153. *
  154. * @public
  155. * @name isEnabled
  156. * @function
  157. * @memberOf mmir.env.media.IAudio.prototype
  158. */
  159. isEnabled: function(){}
  160. };
  161. /**
  162. * Audio object that is used for the sound notifications
  163. * by the {@link mmir.NotificationManager}.
  164. *
  165. * @interface
  166. * @name INotificationSound
  167. * @augments mmir.env.media.IAudio
  168. * @memberOf mmir.env.media
  169. */
  170. var INotificationSound = {
  171. /**
  172. * The name / identifier for the sound.
  173. *
  174. * @public
  175. * @type String
  176. * @name name
  177. * @memberOf mmir.env.media.INotificationSound.prototype
  178. */
  179. name : null,
  180. /**
  181. * Flag for the play status.
  182. *
  183. * @protected
  184. * @type Boolean
  185. * @name isNotificationPlaying
  186. * @memberOf mmir.env.media.INotificationSound.prototype
  187. */
  188. isNotificationPlaying : false,
  189. /**
  190. * Field that holds the value for the repeat number:
  191. * specifies how many times the sound should be played, before
  192. * {@link #isNotificationPlaying} is set to <code>false</code>.
  193. * <p>
  194. * MUST be <code>>= 1</code>, otherwise the sound will not be played.
  195. *
  196. * @protected
  197. * @type Number
  198. * @name repeatNotification
  199. * @memberOf mmir.env.media.INotificationSound.prototype
  200. */
  201. repeatNotification : 0,
  202. /**
  203. * The callback for "finished" events.
  204. *
  205. * @protected
  206. * @type Function
  207. * @name onFinishedListener
  208. * @memberOf mmir.env.media.INotificationSound.prototype
  209. */
  210. onFinishedListener : null,
  211. /**
  212. * The callback for "error" events.
  213. *
  214. * @protected
  215. * @type Function
  216. * @name onErrorListener
  217. * @memberOf mmir.env.media.INotificationSound.prototype
  218. */
  219. onErrorListener : null,
  220. /**
  221. * Field that holds the value for the repeat number:
  222. * specifies how many times the sound should be played, before
  223. * {@link #isNotificationPlaying} is set to <code>false</code>.
  224. * <p>
  225. * MUST be <code>>= 1</code>, otherwise the sound will not be played.
  226. *
  227. * @param {Number} repeatNTimes
  228. * specifies how many times the sound should be played, before
  229. * {@link #isNotificationPlaying} is set to <code>false</code>.
  230. * <br>
  231. * MUST be <code>>= 1</code>, otherwise the sound will not be played.
  232. *
  233. *
  234. * @public
  235. * @function
  236. * @name playNotification
  237. * @memberOf mmir.env.media.INotificationSound.prototype
  238. */
  239. playNotification : function(repeatNTimes){},
  240. /**
  241. * Set callback functions for when the sound has finished playing, and
  242. * for errors.
  243. * <p>
  244. * The sound finishes playing, when its audio object has been played
  245. * <code>repeatNTimes</code> as specified when invoking
  246. * <code>function playNotification(repeatNTimes)</code>.
  247. *
  248. *
  249. * @param {Function} onFinished
  250. * the callback for the finished event
  251. * @param {Function} onError
  252. * the callback for errors
  253. *
  254. * @public
  255. * @function
  256. * @name setCallbacks
  257. * @memberOf mmir.env.media.INotificationSound.prototype
  258. */
  259. setCallbacks : function(onFinished, onError){},
  260. /**
  261. * Clears the "finished" and "error" callbacks.
  262. *
  263. * @public
  264. * @function
  265. * @name clearCallbacks
  266. * @memberOf mmir.env.media.INotificationSound.prototype
  267. */
  268. clearCallbacks : function(){},
  269. /**
  270. * Fires the "finished" event for its callback (if one is set).
  271. *
  272. * @protected
  273. * @function
  274. * @name fireFinished
  275. * @memberOf mmir.env.media.INotificationSound.prototype
  276. */
  277. fireFinished : function(){},
  278. /**
  279. * Fires the "error" event for its callback (if one is set).
  280. *
  281. * @param {any} error
  282. * the error that occurred
  283. *
  284. * @protected
  285. * @function
  286. * @name fireError
  287. * @memberOf mmir.env.media.INotificationSound.prototype
  288. */
  289. fireError : function(error){}
  290. };
  291. /**
  292. * Implementation for showing wait-/ready-indications:
  293. *
  294. * media-modules may signal that they are <code>preparing</code> a resource, and then that
  295. * they are <code>ready</code> via {@link mmir.MediaManager#_preparing} and
  296. * {@link mmir.MediaManager#_ready}.
  297. *
  298. * @interface
  299. * @name IWaitReadyIndicator
  300. * @memberOf mmir.env.media
  301. *
  302. * @see mmir.MediaManager#readyWaitImpl
  303. * @see mmir.env.media.WaitReadyIndicatorImpl
  304. *
  305. * @example
  306. *
  307. * var myWaitReadyImpl = {
  308. * preparing: function(n){
  309. * console.log('preparing: '+m);
  310. * },
  311. * ready: function(n){
  312. * console.log('ready: '+m);
  313. * }
  314. * }
  315. * mmir.media.readyWaitImpl = myWaitReadyImpl;
  316. */
  317. var IWaitReadyIndicator = {
  318. /**
  319. * Indicates that the media plugin <code>pluginName</code> is preparing
  320. * something and that the user should wait.
  321. *
  322. * <p>
  323. * For example, an implementation could show a wait dialog / overlay when this function is called.
  324. *
  325. * @param {String} moduleName
  326. * the module name from which the function was invoked
  327. *
  328. * @public
  329. * @memberOf mmir.env.media.IWaitReadyIndicator.prototype
  330. *
  331. * @see mmir.MediaManager#_preparing
  332. */
  333. preparing: function (moduleName){},
  334. /**
  335. * Indicates that the media plugin <code>pluginName</code> is now ready
  336. * and that the user can begin interacting.
  337. *
  338. * <p>
  339. * For example, an implementation could hide a wait dialog / overlay when this function is called
  340. * (that was previously shown with {@link #preparing}).
  341. *
  342. * @param {String} moduleName
  343. * the module name from which the function was invoked
  344. *
  345. * @public
  346. * @memberOf mmir.env.media.IWaitReadyIndicator.prototype
  347. *
  348. * @see mmir.MediaManager#_ready
  349. */
  350. ready: function(moduleName){}
  351. };