audio.d.ts 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050
  1. /**
  2. * Audio tracks encapsulate and provide a consistent interface to an audio resource.
  3. */
  4. export interface AudioTrack {
  5. /**
  6. * Returns a new independent copy of the track.
  7. * @since 2.28.0
  8. */
  9. clone(): AudioTrack;
  10. /**
  11. * Returns the track's total playtime in seconds, Infinity for a stream, or NaN if no metadata exists.
  12. * @since 2.28.0
  13. */
  14. duration(): number;
  15. /**
  16. * Starts playback of the track and fades it between the specified starting and destination volume levels over
  17. * the specified number of seconds.
  18. * @param duration The number of seconds over which the track should be faded.
  19. * @param toVol The destination volume level.
  20. * @param fromVol The starting volume level. If omitted, defaults to the track's current volume level.
  21. * @since 2.28.0
  22. * @example
  23. * // Fade the track from volume 0 to 1 over 6 seconds.
  24. * aTrack.fade(6, 1, 0);
  25. */
  26. fade(duration: number, toVol: number, fromVol?: number): Promise<void>;
  27. /**
  28. * Starts playback of the track and fades it from the specified volume level to 1 (loudest) over the specified
  29. * number of seconds.
  30. * @param duration The number of seconds over which the track should be faded.
  31. * @param fromVol The starting volume level. If omitted, defaults to the track's current volume level.
  32. * @since 2.29.0
  33. * @example
  34. * // Fade the track in from volume 0 over 5 seconds.
  35. * aTrack.fadeIn(5, 0);
  36. */
  37. fadeIn(duration: number, fromVol?: number): Promise<void>;
  38. /**
  39. * Starts playback of the track and fades it from the specified volume level to 0 (silent) over the specified number
  40. * of seconds.
  41. * @param duration The number of seconds over which the track should be faded.
  42. * @param fromVol The starting volume level. If omitted, defaults to the track's current volume level.
  43. * @since 2.29.0
  44. */
  45. fadeOut(duration: number, fromVol?: number): Promise<void>;
  46. /**
  47. * Interrupts an in-progress fade of the track, or does nothing if no fade is progressing.
  48. * NOTE: This does not alter the volume level.
  49. * @since 2.28.0
  50. */
  51. fadeStop(): void;
  52. /**
  53. * Returns whether enough data has been loaded to play the track through to the end without interruption.
  54. * NOTE: This is an estimate calculated by the browser based upon the currently downloaded data and the download rate.
  55. * @since 2.28.0
  56. */
  57. hasData(): boolean;
  58. /**
  59. * Returns whether, at least, the track's metadata has been loaded.
  60. * @since 2.28.0
  61. */
  62. hasMetadata(): boolean;
  63. /**
  64. * Returns whether none of the track's data has been loaded.
  65. * @since 2.28.0
  66. */
  67. hasNoData(): boolean;
  68. /**
  69. * Returns whether, at least, some of the track's data has been loaded.
  70. * TIP: The <AudioTrack>.hasData() method is generally more useful.
  71. * @since 2.28.0
  72. */
  73. hasSomeData(): boolean;
  74. /**
  75. * Returns whether any valid sources were registered.
  76. * @since 2.28.0
  77. */
  78. hasSource(): boolean;
  79. /**
  80. * Returns whether playback of the track has ended.
  81. * @since 2.28.0
  82. */
  83. isEnded(): boolean;
  84. /**
  85. * Returns whether a fade is in-progress on the track.
  86. * @since 2.28.0
  87. */
  88. isFading(): boolean;
  89. /**
  90. * Returns whether an error has occurred.
  91. * @since 2.28.0
  92. */
  93. isFailed(): boolean;
  94. /**
  95. * Returns whether the track is loading data.
  96. * @since 2.28.0
  97. */
  98. isLoading(): boolean;
  99. /**
  100. * Returns whether playback of the track has been paused.
  101. * @since 2.28.0
  102. */
  103. isPaused(): boolean;
  104. /**
  105. * Returns whether the track is playing.
  106. * @since 2.28.0
  107. */
  108. isPlaying(): boolean;
  109. /**
  110. * Returns whether the track is seeking.
  111. * @since 2.28.0
  112. */
  113. isSeeking(): boolean;
  114. /**
  115. * Returns whether playback of the track has been stopped.
  116. * @since 2.29.0
  117. */
  118. isStopped(): boolean;
  119. /**
  120. * Returns whether the track is currently unavailable for playback. Possible reasons include: no valid sources are
  121. * registered, no sources are currently loaded, an error has occurred.
  122. * @since 2.28.0
  123. */
  124. isUnavailable(): boolean;
  125. /**
  126. * Returns whether the track's sources are currently unloaded.
  127. * @since 2.28.0
  128. */
  129. isUnloaded(): boolean;
  130. /**
  131. * Pauses playback of the track and, if it's not already in the process of loading, forces it to drop any existing
  132. * data and begin loading.
  133. * WARNING: This should not be done lightly if your audio sources are on the network, as it forces players to begin downloading them.
  134. * @since 2.28.0
  135. */
  136. load(): void;
  137. /**
  138. * Gets the track's repeating playback state (default: false).
  139. */
  140. loop(): boolean;
  141. /**
  142. * Sets the track's repeating playback state (default: false).
  143. * @param state The loop state.
  144. * @returns a reference to the current AudioTrack instance for chaining.
  145. * @since 2.28.0
  146. */
  147. loop(state: boolean): this;
  148. /**
  149. * Gets the track's volume mute state (default: false).
  150. * @since 2.28.0
  151. */
  152. mute(): boolean;
  153. /**
  154. * Sets the track's volume mute state
  155. * @param state The mute state.
  156. * @returns a reference to the current AudioTrack instance for chaining.
  157. * @since 2.28.0
  158. */
  159. mute(state: boolean): this;
  160. /**
  161. * Removes event handlers from the track. Returns a reference to the current AudioTrack instance for chaining.
  162. * NOTE: Shorthand for jQuery's .off() method applied to each of the audio elements.
  163. * WARNING: The SimpleAudio APIs use events internally for various pieces of functionality. To prevent
  164. * conflicts, it is strongly suggested that you specify a custom user namespace—e.g., .myEvents—when attaching
  165. * your own handlers. It is further strongly suggested that you provide that same custom user namespace when
  166. * removing them.
  167. * @see jQuery.off()
  168. * @param events One or more space-separated event types and optional namespaces, or just namespaces,
  169. * such as "click", "keydown.myPlugin", or ".myPlugin".
  170. * @param selector A selector which should match the one originally passed to .on() when attaching event handlers.
  171. * @param handler A handler function previously attached for the event(s), or the special value false.
  172. * @example
  173. * // Remove any handlers for the ended event.
  174. * someTracks.off('ended.myEvents');
  175. * @since 2.28.0
  176. */
  177. off(events: string | object | JQuery.Event, selector?: string, handler?: (event: JQuery.Event) => void): AudioTrack;
  178. /**
  179. * Attaches event handlers to the track. Returns a reference to the current AudioTrack instance for chaining.
  180. * @param events
  181. * @param selector
  182. * @param data
  183. * @param handler
  184. * @since 2.28.0
  185. */
  186. on(
  187. events: string | object | JQuery.Event,
  188. selector?: string,
  189. data?: any,
  190. handler?: (event: JQuery.Event) => void,
  191. ): AudioTrack;
  192. /**
  193. * Attaches single-use event handlers to the track. Returns a reference to the current AudioTrack
  194. * instance for chaining.
  195. * @param events
  196. * @param selector
  197. * @param data
  198. * @param handler
  199. * @since 2.28.0
  200. */
  201. one(
  202. events: string | object | JQuery.Event,
  203. selector?: string,
  204. data?: any,
  205. handler?: (event: JQuery.Event) => void,
  206. ): AudioTrack;
  207. /**
  208. * Pauses playback of the track.
  209. * @since 2.28.0
  210. */
  211. pause(): void;
  212. /**
  213. * Begins playback of the track.
  214. * @since 2.28.0
  215. */
  216. play(): Promise<void>;
  217. /**
  218. * Begins playback of the track or, failing that, sets the track to begin playback as soon as the player has interacted
  219. * with the document.
  220. * @since 2.28.0
  221. */
  222. playWhenAllowed(): void;
  223. /**
  224. * Returns how much remains of the track's total playtime in seconds, Infinity for a stream, or NaN if no metadata exists.
  225. * @since 2.28.0
  226. */
  227. remaining(): number;
  228. /**
  229. * Stops playback of the track.
  230. * @since 2.28.0
  231. */
  232. stop(): void;
  233. /**
  234. * Gets the track's current time in seconds.
  235. * @since 2.28.0
  236. */
  237. time(): number;
  238. /**
  239. * Sets the track's current time in seconds.
  240. * @param seconds The time to set. Valid values are floating-point numbers in the range 0 (start) to the maximum
  241. * duration—e.g., 60 is 60 is sixty seconds in, 90.5 is ninety-point-five seconds in.
  242. * @since 2.28.0
  243. */
  244. time(seconds: number): this;
  245. /**
  246. * Stops playback of the track and forces it to drop any existing data.
  247. * NOTE: Once unloaded, playback cannot occur until the track's data is loaded again.
  248. * @since 2.28.0
  249. */
  250. unload(): void;
  251. /**
  252. * Gets the track's volume level (default: 1).
  253. */
  254. volume(): number;
  255. /**
  256. * Sets the track's volume level (default: 1).
  257. * @param level The volume level to set. Valid values are floating-point numbers in the range 0 (silent) to 1 (loudest)
  258. * — e.g., 0 is 0%, 0.5 is 50%, 1 is 100%.
  259. * @returns a reference to the current AudioTrack instance for chaining.
  260. * @since 2.28.0
  261. */
  262. volume(level: number): this;
  263. }
  264. /**
  265. * Audio runners are useful for performing actions on multiple tracks at once.
  266. * @since 2.28.0
  267. */
  268. export interface AudioRunner {
  269. /**
  270. * Starts playback of the selected tracks and fades them between the specified starting and destination volume levels
  271. * over the specified number of seconds.
  272. * @param duration The number of seconds over which the tracks should be faded.
  273. * @param toVol The destination volume level.
  274. * @param fromVol The starting volume level. If omitted, defaults to the tracks' current volume level.
  275. * @example
  276. * // Fade the selected tracks from volume 0 to 1 over 6 seconds.
  277. * someTracks.fade(6, 1, 0);
  278. * @since 2.28.0
  279. */
  280. fade(duration: number, toVol: number, fromVol?: number): void;
  281. /**
  282. * Starts playback of the selected tracks and fades them from the specified volume level to 1 (loudest) over the
  283. * specified number of seconds.
  284. * @param duration The number of seconds over which the tracks should be faded.
  285. * @param fromVol The starting volume level. If omitted, defaults to the tracks' current volume level.
  286. *
  287. * @example
  288. * // Fade the selected tracks in from volume 0 over 5 seconds.
  289. * someTracks.fadeIn(5, 0);
  290. * @since 2.28.0
  291. */
  292. fadeIn(duration: number, fromVol?: number): void;
  293. /**
  294. * Starts playback of the selected tracks and fades them from the specified volume level to 0 (silent) over the
  295. * specified number of seconds.
  296. * @param duration The number of seconds over which the tracks should be faded.
  297. * @param fromVol The starting volume level. If omitted, defaults to the tracks' current volume level.
  298. * @example
  299. * // Fade the selected tracks out from volume 1 over 8 seconds.
  300. * someTracks.fadeOut(8, 1);
  301. * @since 2.28.0
  302. */
  303. fadeOut(duration: number, fromVol?: number): void;
  304. /**
  305. * Interrupts an in-progress fade of the selected tracks, or does nothing if no fade is progressing.
  306. *
  307. * NOTE: This does not alter the volume level.
  308. * @example
  309. * someTracks.fadeStop();
  310. * @since 2.28.0
  311. */
  312. fadeStop(): void;
  313. /**
  314. * Pauses playback of the selected tracks and, if they're not already in the process of loading, forces them to
  315. * drop any existing data and begin loading.
  316. * WARNING: This should not be done lightly if your audio sources are on the network, as it forces players to
  317. * begin downloading them.
  318. * @example
  319. * someTracks.load();
  320. * @since 2.28.0
  321. */
  322. load(): void;
  323. /**
  324. * Sets the selected tracks' repeating playback state (default: false). Returns a reference to the current
  325. * AudioRunner instance for chaining.
  326. * @param state The loop state (false by default).
  327. * @since 2.28.0
  328. * @example
  329. * // Loop the selected tracks.
  330. * someTracks.loop(true);
  331. *
  332. * // Unloop the selected tracks.
  333. * someTracks.loop(false);
  334. */
  335. loop(state?: boolean): this;
  336. /**
  337. * Sets the selected tracks' volume mute state (default: false). Returns a reference to the current
  338. * AudioRunner instance for chaining.
  339. * @param state The mute state (false by default).
  340. * @example
  341. * // Mute the selected tracks' volume.
  342. * someTracks.mute(true);
  343. *
  344. * // Unmute the selected tracks' volume.
  345. * someTracks.mute(false);
  346. * @since 2.28.0
  347. */
  348. mute(state?: boolean): this;
  349. /**
  350. * Removes event handlers from the selected tracks. Returns a reference to the current AudioRunner
  351. * instance for chaining.
  352. * NOTE: Shorthand for jQuery's .off() method applied to each of the audio elements.
  353. * WARNING: The SimpleAudio APIs use events internally for various pieces of functionality. To prevent
  354. * conflicts, it is strongly suggested that you specify a custom user namespace—e.g., .myEvents—when attaching
  355. * your own handlers. It is further strongly suggested that you provide that same custom user namespace when
  356. * removing them.
  357. * @see jQuery.off()
  358. * @param events One or more space-separated event types and optional namespaces, or just namespaces,
  359. * such as "click", "keydown.myPlugin", or ".myPlugin".
  360. * @param selector A selector which should match the one originally passed to .on() when attaching event handlers.
  361. * @param handler A handler function previously attached for the event(s), or the special value false.
  362. * @example
  363. * // Remove any handlers for the ended event.
  364. * someTracks.off('ended.myEvents');
  365. * @since 2.28.0
  366. */
  367. off(events: string | object | JQuery.Event, selector?: string, handler?: (event: JQuery.Event) => void): this;
  368. /**
  369. * Attaches event handlers to the selected tracks. Returns a reference to the current AudioRunner instance for chaining.
  370. * @param events
  371. * @param selector
  372. * @param data
  373. * @param handler
  374. * @since 2.28.0
  375. */
  376. on(
  377. events: string | object | JQuery.Event,
  378. selector?: string,
  379. data?: any,
  380. handler?: (event: JQuery.Event) => void,
  381. ): this;
  382. /**
  383. * Attaches single-use event handlers to the selected tracks. Returns a reference to the current AudioRunner
  384. * instance for chaining.
  385. * @param events
  386. * @param selector
  387. * @param data
  388. * @param handler
  389. * @since 2.28.0
  390. */
  391. one(
  392. events: string | object | JQuery.Event,
  393. selector?: string,
  394. data?: any,
  395. handler?: (event: JQuery.Event) => void,
  396. ): this;
  397. /**
  398. * Pauses playback of the selected tracks.
  399. * @since 2.28.0
  400. * @example
  401. * someTracks.pause();
  402. */
  403. pause(): void;
  404. /**
  405. * Begins playback of the selected tracks.
  406. * @since 2.28.0
  407. */
  408. play(): void;
  409. /**
  410. * Begins playback of the selected tracks or, failing that, sets the tracks to begin playback as soon as
  411. * the player has interacted with the document.
  412. * @since 2.28.0
  413. */
  414. playWhenAllowed(): void;
  415. /**
  416. * Stops playback of the selected tracks.
  417. * @since 2.28.0
  418. */
  419. stop(): void;
  420. /**
  421. * Sets the selected tracks' current time in seconds. Returns a reference to the current AudioRunner
  422. * instance for chaining.
  423. * @param seconds The time to set. Valid values are floating-point numbers in the range 0 (start) to
  424. * the maximum duration—e.g., 60 is 60 is sixty seconds in, 90.5 is ninety-point-five seconds in.
  425. * @since 2.28.0
  426. * @example
  427. * // Set the selected tracks' current time to 30 seconds from their beginning.
  428. * someTracks.time(30);
  429. */
  430. time(seconds: number): this;
  431. /**
  432. * Stops playback of the selected tracks and forces them to drop any existing data.
  433. *
  434. * NOTE: Once unloaded, playback cannot occur until the selected tracks' data is loaded again.
  435. * @since 2.28.0
  436. */
  437. unload(): void;
  438. /**
  439. * Sets the selected tracks' volume level (default: 1). Returns a reference to the current AudioRunner
  440. * instance for chaining.
  441. * @param level The volume level to set. Valid values are floating-point numbers in the range 0 (silent)
  442. * to 1 (loudest)—e.g., 0 is 0%, 0.5 is 50%, 1 is 100%.
  443. * @since 2.28.0
  444. * @example
  445. * // Set the selected tracks' volume level to 75%.
  446. * someTracks.volume(0.75);
  447. */
  448. volume(level: number): this;
  449. }
  450. /**
  451. * Audio lists (playlists) are useful for playing tracks in a sequence—i.e., one after another.
  452. */
  453. export interface AudioList {
  454. /**
  455. * Returns the playlist's total playtime in seconds, Infinity if it contains any streams, or NaN if no metadata exists.
  456. * @since 2.28.0
  457. */
  458. duration(): number;
  459. /**
  460. * Starts playback of the playlist and fades the currently playing track between the specified starting and destination
  461. * volume levels over the specified number of seconds.
  462. * @param duration The number of seconds over which the currently playing track should be faded.
  463. * @param toVol The destination volume level.
  464. * @param fromVol The starting volume level. If omitted, defaults to the currently playing track's current volume level.
  465. * @since 2.29.0
  466. * @example
  467. * // Fade the playlist from volume 0 to 1 over 6 seconds.
  468. * aList.fade(6, 1, 0);
  469. */
  470. fade(duration: number, toVol: number, fromVol?: number): Promise<void>;
  471. /**
  472. * Starts playback of the playlist and fades the currently playing track from the specified volume level to 1 (loudest)
  473. * over the specified number of seconds.
  474. * @param duration The number of seconds over which the currently playing track should be faded.
  475. * @param fromVol The starting volume level. If omitted, defaults to the currently playing track's current volume level.
  476. * @since 2.29.0
  477. * @example
  478. * // Fade the playlist in from volume 0 over 5 seconds.
  479. * aList.fadeIn(5, 0);
  480. */
  481. fadeIn(duration: number, fromVol?: number): Promise<void>;
  482. /**
  483. * Starts playback of the playlist and fades the currently playing track from the specified volume level to 0 (silent)
  484. * over the specified number of seconds.
  485. * @param duration The number of seconds over which the currently playing track should be faded.
  486. * @param fromVol The starting volume level. If omitted, defaults to the currently playing track's current volume level.
  487. * @since 2.29.0
  488. * @example
  489. * // Fade the playlist out from volume 1 over 8 seconds.
  490. * aList.fadeOut(8, 1);
  491. */
  492. fadeOut(duration: number, fromVol?: number): Promise<void>;
  493. /**
  494. * Interrupts an in-progress fade of the currently playing track, or does nothing if no fade is progressing.
  495. * NOTE: This does not alter the volume level.
  496. * @since 2.29.0
  497. */
  498. fadeStop(): void;
  499. /**
  500. * Returns whether playback of the playlist has ended.
  501. * @since 2.28.0
  502. */
  503. isEnded(): boolean;
  504. /**
  505. * Returns whether a fade is in-progress on the currently playing track.
  506. * @since 2.29.0
  507. */
  508. isFading(): boolean;
  509. /**
  510. * Returns whether playback of the playlist has been paused.
  511. * @since 2.28.0
  512. */
  513. isPaused(): boolean;
  514. /**
  515. * Returns whether the playlist is playing.
  516. * @since 2.28.0
  517. */
  518. isPlaying(): boolean;
  519. /**
  520. * Returns whether playback of the playlist has been stopped.
  521. * @since 2.29.0
  522. */
  523. isStopped(): boolean;
  524. /**
  525. * Pauses playback of the playlist and, if they're not already in the process of loading, forces its tracks to drop
  526. * any existing data and begin loading.
  527. *
  528. * WARNING: This should not be done lightly if your audio sources are on the network, as it forces players to begin
  529. * downloading them.
  530. * @since 2.28.0
  531. */
  532. load(): void;
  533. /**
  534. * Gets the playlist's repeating playback state (default: false).
  535. * @since 2.28.0
  536. */
  537. loop(): boolean;
  538. /**
  539. * Sets the playlist's repeating playback state (default: false).
  540. * @param state The loop state.
  541. * @returns a reference to the current AudioList instance for chaining.
  542. * @since 2.28.0
  543. */
  544. loop(state: boolean): this;
  545. /**
  546. * Gets the playlist's volume mute state (default: false).
  547. * @since 2.28.0
  548. */
  549. mute(): boolean;
  550. /**
  551. * Gets or sets the playlist's volume mute state (default: false).
  552. * @param state The mute state.
  553. * @returns a reference to the current AudioList instance for chaining.
  554. * @since 2.28.0
  555. */
  556. mute(state: boolean): this;
  557. /**
  558. * Pauses playback of the playlist.
  559. * @since 2.28.0
  560. */
  561. pause(): void;
  562. /**
  563. * Begins playback of the playlist.
  564. * @since 2.29.0
  565. */
  566. play(): Promise<void>;
  567. /**
  568. * Begins playback of the playlist or, failing that, sets the playlist to begin playback as soon as the player has
  569. * interacted with the document.
  570. * @since 2.29.0
  571. */
  572. playWhenAllowed(): void;
  573. /**
  574. * Returns how much remains of the playlist's total playtime in seconds, Infinity if it contains any streams,
  575. * or NaN if no metadata exists.
  576. * @since 2.28.0
  577. */
  578. remaining(): number;
  579. /**
  580. * Gets the playlist's randomly shuffled playback state (default: false).
  581. * @since 2.28.0
  582. */
  583. shuffle(): boolean;
  584. /**
  585. * Sets the playlist's randomly shuffled playback state (default: false).
  586. * @param state The shuffle state.
  587. * @returns a reference to the current AudioList instance for chaining.
  588. * @since 2.28.0
  589. */
  590. shuffle(state: boolean): this;
  591. /**
  592. * Skips ahead to the next track in the playlist, if any.
  593. * @since 2.28.0
  594. */
  595. skip(): void;
  596. /**
  597. * Stops playback of the playlist.
  598. * @since 2.28.0
  599. */
  600. stop(): void;
  601. /**
  602. * Returns the playlist's current time in seconds, or NaN if no metadata exists.
  603. * @since 2.28.0
  604. */
  605. time(): number;
  606. /**
  607. * Stops playback of the playlist and forces its tracks to drop any existing data.
  608. * NOTE: Once unloaded, playback cannot occur until the track's data is loaded again.
  609. * @since 2.28.0
  610. */
  611. unload(): void;
  612. /**
  613. * Gets the playlist's volume level (default: 1).
  614. */
  615. volume(): number;
  616. /**
  617. * Sets the playlist's volume level (default: 1).
  618. * @param level The volume level to set. Valid values are floating-point numbers in the range 0 (silent) to 1
  619. * (loudest)—e.g., 0 is 0%, 0.5 is 50%, 1 is 100%.
  620. * @returns a reference to the current AudioList instance for chaining.
  621. */
  622. volume(level: number): this;
  623. }
  624. /**
  625. * The core audio subsystem and backend for the audio macros.
  626. *
  627. * The audio subsystem is based upon the HTML Media Elements APIs and comes with some built-in limitations:
  628. *
  629. * 1. True gapless transitions between tracks is not supported.
  630. * 2. In mobile browsers, playback volume is controlled by the device hardware. Thus, all volume adjustments are ignored by the
  631. * device, though muting should work normally.
  632. * 3. In mobile browsers and, more recently, most desktop browsers, playback must be initiated by the player—generally via
  633. * click/touch. In these cases, audio will not automatically play on the starting passage, nor is it likely to play if initiated
  634. * from within asynchronous code—e.g., via <<timed>>—though this ultimately depends on various factors. A simple solution for the
  635. * former is to use some kind of click/touch-through screen—e.g., a splash screen, which the player goes through to the real starting
  636. * passage. The latter is harder to resolve, so is best avoided.
  637. * 4. The load and playback states of tracks are not currently recorded within the active play session or saves. Thus, if you need
  638. * either to be recoverable, then you'll have to handle that yourself.
  639. */
  640. export interface SimpleAudioAPI {
  641. /**
  642. * Pauses playback of all currently registered tracks and, if they're not already in the process of loading, force them to drop any
  643. * existing data and begin loading.
  644. * WARNING: This should not be done lightly if your audio sources are on the network, as it forces players to begin downloading them.
  645. * @since 2.28.0
  646. */
  647. load(): void;
  648. /**
  649. * Displays the loading screen until all currently registered audio tracks have either loaded to a playable state or aborted loading
  650. * due to errors. The loading process is as described in @see SimpleAudio.load().
  651. * WARNING: This should not be done lightly if your audio sources are on the network, as it forces players to begin downloading them.
  652. * @since 2.28.0
  653. */
  654. loadWithScreen(): void;
  655. /**
  656. * Gets or sets the mute state for the master volume (default: false).
  657. * @since 2.28.0
  658. */
  659. mute(): boolean;
  660. mute(state: boolean): void;
  661. /**
  662. * Gets or sets the mute-on-hidden state for the master volume (default: false). The mute-on-hidden state controls whether the
  663. * master volume is automatically muted/unmuted when the story's browser tab loses/gains visibility. Loss of visibility is defined
  664. * as when the browser window is either switched to another tab or minimized.
  665. * @since 2.28.0
  666. */
  667. muteOnHidden(): boolean;
  668. muteOnHidden(state: boolean): void;
  669. /**
  670. * Returns an AudioRunner instance for the tracks matching the given selector.
  671. * @param selector The list of audio track(s) and/or group ID(s), separated by spaces. There are several predefined group
  672. * IDs (:all, :looped, :muted, :paused, :playing). The :not() group modifier syntax (groupId:not(selector)) allows a group
  673. * to have some of its tracks excluded from selection.
  674. * @since 2.28.0
  675. * @example
  676. * // Basic usage
  677. * SimpleAudio.select(":ui"); // Returns the AudioRunner instance for the tracks matching ":ui"
  678. * @example
  679. * // Typical usage
  680. * // Return the AudioTrack instance matching "swamped" and do something with it
  681. * SimpleAudio.select("swamped").volume(1).play();
  682. *
  683. * // Start playback of paused audio tracks
  684. * SimpleAudio.select(":paused").play();
  685. *
  686. * // Pause playback of playing audio tracks
  687. * SimpleAudio.select(":playing").pause();
  688. *
  689. * // Stop playback of playing audio tracks
  690. * SimpleAudio.select(":playing").stop();
  691. *
  692. * // Stop playback of all audio tracks (not uniquely part of a playlist)
  693. * SimpleAudio.select(":all").stop();
  694. *
  695. * // Stop playback of playing audio tracks except those in the ":ui" group
  696. * SimpleAudio.select(":playing:not(:ui)").stop();
  697. *
  698. * // Change the volume of all audio tracks except those in the ":ui" group
  699. * // to 40%, without changing the current playback state
  700. * SimpleAudio.select(":all:not(:ui)").volume(0.40);
  701. */
  702. select(selector: string): AudioRunner | null;
  703. /**
  704. * Stops playback of all currently registered tracks.
  705. * @since 2.28.0
  706. */
  707. stop(): void;
  708. /**
  709. * Stops playback of all currently registered tracks and force them to drop any existing data.
  710. * NOTE: Once a track has been unloaded, playback cannot occur until it is reloaded.
  711. * @since 2.28.0
  712. */
  713. unload(): void;
  714. /**
  715. * Gets the master volume level (default: 1).
  716. */
  717. volume(): number;
  718. /**
  719. * Sets the master volume level (default: 1).
  720. * @param level The volume level to set. Valid values are floating-point numbers in the range 0 (silent) to 1
  721. * (loudest)—e.g., 0 is 0%, 0.5 is 50%, 1 is 100%.
  722. * @since 2.28.0
  723. * @example
  724. * // Get the current master volume level.
  725. * var currentMasterVolume = SimpleAudio.volume();
  726. *
  727. * // Set the master volume level to 75%.
  728. * SimpleAudio.volume(0.75);
  729. */
  730. volume(level: number): void;
  731. readonly tracks: {
  732. /**
  733. * Adds an audio track with the given track ID.
  734. * @param trackId The ID of the track, which will be used to reference it.
  735. * @param sources The audio sources for the track, which may be a list of sources or an array. Only one is required,
  736. * though supplying additional sources in differing formats is recommended, as no single format is supported by all browsers.
  737. * A source must be either a URL (absolute or relative) to an audio resource, the name of an audio passage, or a data URI. In
  738. * rare cases where the audio format cannot be automatically detected from the source (URLs are parsed for a file extension,
  739. * data URIs are parsed for the media type), a format specifier may be prepended to the front of each source to manually
  740. * specify the format (syntax: formatId|, where formatId is the audio format—generally, whatever the file extension would
  741. * normally be; e.g., mp3, mp4, ogg, weba, wav).
  742. * @example
  743. * // Cache a track with the ID "boom" and one source via relative URL
  744. * SimpleAudio.tracks.add("boom", "media/audio/explosion.mp3");
  745. *
  746. * // Cache a track with the ID "boom" and one source via audio passage
  747. * SimpleAudio.tracks.add("boom", "explosion");
  748. *
  749. * // Cache a track with the ID "bgm_space" and two sources via relative URLs
  750. * SimpleAudio.tracks.add("bgm_space", "media/audio/space_quest.mp3", "media/audio/space_quest.ogg");
  751. *
  752. * // Cache a track with the ID "what" and one source via URL with a format specifier
  753. * SimpleAudio.tracks.add("what", "mp3|http://an-audio-service.com/a-user/a-track-id");
  754. *
  755. * @since 2.28.0
  756. */
  757. add(trackId: string, ...sources: readonly string[]): void;
  758. /**
  759. * Deletes all audio tracks.
  760. * NOTE: Cannot delete tracks solely under the control of a playlist.
  761. * @since 2.28.0
  762. */
  763. clear(): void;
  764. /**
  765. * Deletes the audio track with the given track ID.
  766. *
  767. * NOTE: Cannot delete tracks solely under the control of a playlist.
  768. * WARNING: Does not currently remove the track from either groups or playlists. Thus, any groups or playlists
  769. * containing the deleted track should be rebuilt.
  770. * @param trackId The ID of the track.
  771. * @since 2.28.0
  772. * @example
  773. * SimpleAudio.tracks.delete("bgm_space");
  774. */
  775. delete(trackId: string): void;
  776. /**
  777. * Returns the AudioTrack instance with the given track ID, or null on failure.
  778. * NOTE: To affect multiple tracks and/or groups at once, see the SimpleAudio.select() method.
  779. * Returns the AudioTrack instance with the given track ID, or null on failure.
  780. * @param trackId The ID of the track.
  781. * @since 2.28.0
  782. * @example
  783. * SimpleAudio.tracks.get("swamped") → Returns the AudioTrack instance matching "swamped"
  784. * @example
  785. * // Return the AudioTrack instance matching "swamped" and do something with it
  786. * SimpleAudio.tracks.get("swamped").volume(1).play();
  787. */
  788. get(trackId: string): AudioTrack | null;
  789. /**
  790. * Returns whether an audio track with the given track ID exists.
  791. * @param trackId The ID of the track.
  792. */
  793. has(trackId: string): boolean;
  794. };
  795. readonly groups: {
  796. /**
  797. * Adds an audio group with the given group ID. Groups are useful for applying actions to multiple tracks
  798. * simultaneously and/or excluding the included tracks from a larger set when applying actions.
  799. * @param groupId The ID of the group, which will be used to reference it and must begin with a colon.
  800. * NOTE: There are several predefined group IDs (:all, :looped, :muted, :paused, :playing) and the :not group
  801. * modifier that cannot be reused/overwritten.
  802. * @param trackIds The IDs of the tracks to make part of the group, which may be a list of track IDs or an array.
  803. * @since 2.28.0
  804. * @example
  805. * // Set up a group ":ui" with the tracks: "ui_beep", "ui_boop", and "ui_swish"
  806. * SimpleAudio.groups.add(":ui", "ui_beep", "ui_boop", "ui_swish");
  807. */
  808. add(groupId: string, ...trackIds: readonly string[]): void;
  809. /**
  810. * Deletes all audio groups.
  811. * NOTE: Only deletes the groups themselves, does not affect their component tracks.
  812. * @since 2.28.0
  813. */
  814. clear(): void;
  815. /**
  816. * Deletes the audio group with the given group ID.
  817. * NOTE: Only deletes the group itself, does not affect its component tracks.
  818. * @param groupId The ID of the group.
  819. * @since 2.28.0
  820. * @example
  821. * SimpleAudio.groups.delete(":ui");
  822. */
  823. delete(groupId: string): void;
  824. /**
  825. * Returns the array of track IDs with the given group ID, or null on failure.
  826. * NOTE: To actually affect multiple tracks and/or groups, see the SimpleAudio.select() method.
  827. * @param groupId The ID of the group.
  828. * @since 2.28.0
  829. * @example
  830. * SimpleAudio.groups.get(":ui") → Returns the array of track IDs matching ":ui"
  831. */
  832. get(groupId: string): string[];
  833. /**
  834. * Returns whether an audio group with the given group ID exists.
  835. * @param groupId The ID of the group.
  836. * @since 2.28.0
  837. */
  838. has(groupId: string): boolean;
  839. };
  840. readonly lists: {
  841. /**
  842. * Adds a playlist with the given list ID. Playlists are useful for playing tracks in a sequence—i.e., one after another.
  843. * @param listId The ID of the list, which will be used to reference it
  844. * @param sources The track IDs or descriptors of the tracks to make part of the list, which may be specified as a list or an array.
  845. * Descriptor objects:
  846. * * **Existing track form: `{ id, [own], [volume] }`**
  847. * * **`id`:** (*string*) The ID of an existing track.
  848. * * **`own`:** (optional, *boolean*) When `true`, signifies that the playlist should create its own independent copy
  849. * of the track, rather than simply referencing the existing instance. Owned copies are solely under the control of their
  850. * playlist and cannot be selected with either the [`SimpleAudio.tracks.get()` method](#simpleaudio-api-method-tracks-get)
  851. * or the [`SimpleAudio.select()` method](#simpleaudio-api-method-select).
  852. * * **`volume`:** (optional, *number*) The base volume level of the track within the playlist. If omitted, defaults to
  853. * the track's current volume. Valid values are floating-point numbers in the range `0` (silent) to `1` (loudest)—e.g.,
  854. * `0` is 0%, `0.5` is 50%, `1` is 100%.
  855. * * **New track form: `{ sources, [volume] }`**
  856. * * **`sources`:** (*string array*) The audio sources for the track. Only one is required, though supplying additional
  857. * sources in differing formats is recommended, as no single format is supported by all browsers. A source must be either
  858. * a URL (absolute or relative) to an audio resource, the name of an audio passage, or a data URI. In rare cases where the
  859. * audio format cannot be automatically detected from the source (URLs are parsed for a file extension, data URIs are parsed
  860. * for the media type), a format specifier may be prepended to the front of each source to manually specify the format
  861. * (syntax: `formatId|`, where `formatId` is the audio format—generally, whatever the file extension would normally be; e.g.,
  862. * `mp3`, `mp4`, `ogg`, `weba`, `wav`).
  863. * * **`volume`:** (optional, *number*) The base volume level of the track within the playlist. If omitted, defaults to `1`
  864. * (loudest). Valid values are floating-point numbers in the range `0` (silent) to `1` (loudest)—e.g., `0` is 0%, `0.5`
  865. * is 50%, `1` is 100%.
  866. *
  867. * @example
  868. * // Basic usage with track IDs
  869. * // Add existing tracks at their current volumes
  870. * SimpleAudio.lists.add("bgm_lacuna", "swamped", "heavens_a_lie", "closer", "to_the_edge");
  871. *
  872. * @example
  873. * // Using a mix of track IDs and descriptors
  874. * SimpleAudio.lists.add("bgm_lacuna",
  875. * // Add existing track "swamped" at its current volume
  876. * "swamped",
  877. * // Add existing track "heavens_a_lie" at 50% volume
  878. * {
  879. * id : "heavens_a_lie",
  880. * volume : 0.5
  881. * },
  882. * // Add an owned copy of existing track "closer" at its current volume
  883. * {
  884. * id : "closer",
  885. * own : true
  886. * },
  887. * // Add an owned copy of existing track "to_the_edge" at 100% volume
  888. * {
  889. * id : "to_the_edge",
  890. * own : true,
  891. * volume : 1
  892. * }
  893. * );
  894. *
  895. * @example
  896. * // Using descriptors with sources
  897. * SimpleAudio.lists.add("bgm_lacuna",
  898. * // Add a track from the given sources at the default volume (100%)
  899. * {
  900. * sources : ["media/audio/Swamped.mp3"]
  901. * },
  902. * // Add a track from the given sources at 50% volume
  903. * {
  904. * sources : ["media/audio/Heaven's_A_Lie.mp3"],
  905. * volume : 0.5
  906. * },
  907. * // Add a track from the given sources at the default volume (100%)
  908. * {
  909. * sources : ["media/audio/Closer.mp3"]
  910. * },
  911. * // Add a track from the given sources at 100% volume
  912. * {
  913. * sources : ["media/audio/To_The_Edge.mp3"],
  914. * volume : 1
  915. * }
  916. * );
  917. */
  918. add(
  919. listId: string,
  920. ...sources: ReadonlyArray<
  921. string | {
  922. id?: string | undefined;
  923. sources?: string[] | undefined;
  924. own?: boolean | undefined;
  925. volume?: number | undefined;
  926. }
  927. >
  928. ): void;
  929. /**
  930. * Deletes all playlists.
  931. * @since 2.28.0
  932. */
  933. clear(): void;
  934. /**
  935. * Deletes the playlist with the given list ID
  936. * @param listId The ID of the playlist.
  937. * @since 2.28.0
  938. */
  939. delete(listId: string): void;
  940. /**
  941. * Returns the AudioList instance with the given list ID, or null on failure.
  942. * @param listId The ID of the playlist.
  943. * @returns AudioList instance with the given list ID, or null on failure.
  944. */
  945. get(listId: string): AudioList | null;
  946. /**
  947. * Returns whether a playlist with the given list ID exists.
  948. * @param listId The ID of the playlist.
  949. */
  950. has(listId: string): boolean;
  951. };
  952. }
  953. export {};