Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

zaudio.d.ts 7.0 KiB

2 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. interface audio {
  2. src: string;
  3. title: string;
  4. singer: string;
  5. coverImgUrl: string;
  6. }
  7. interface audioInfo extends audio {
  8. current: string;
  9. duration: string;
  10. duration_value: number;
  11. current_value: number;
  12. }
  13. declare enum zaudioCbName {
  14. onWaiting = "waiting",
  15. onError = "error",
  16. onTimeUpdate = "playing",
  17. onCanplay = "canPlay",
  18. onPause = "pause",
  19. onEnded = "ended",
  20. setAudio = "setAudio",
  21. updateAudio = "updateAudio",
  22. seek = "seek",
  23. onStop = "stop",
  24. syncStateOn = "syncStateOn"
  25. }
  26. import { EventBus } from "./util";
  27. /**
  28. * ZAudio类
  29. * @class ZAudio
  30. * @constructor
  31. * @param {String} defaultCover 音频默认封面
  32. * @param {Boolean} continuePlay 继续播放,错误播放或结束播放后执行
  33. * @param {Boolean} autoPlay 自动播放,部分浏览器不支持
  34. * @property {Number} renderIndex 当前渲染索引
  35. * @property {<audioinfo>} renderinfo 当前渲染数据
  36. * @property {Array<audio>} audiolist 音频列表数组
  37. * @property {<audioinfo>} playinfo 当前播放数据
  38. * @property {Boolean} paused 音频暂停状态
  39. * @property {Number} playIndex 当前播放索引
  40. * @property {Boolean} renderIsPlay 渲染与播放是否一致
  41. *
  42. * @method on(event, action, fn) 回调函数注册业务事件
  43. * @method off(event, action) 回调函数中卸载业务事件
  44. * @method setRender(data) 指定音频, 渲染到zaudio组件
  45. * @method syncRender() 同步并渲染当前的播放状态
  46. * @method operate(index) 播放或暂停指定索引的音频
  47. * @method setAudio(list) 覆盖音频列表
  48. * @method updateAudio(list) 添加音频列表
  49. * @method stop() 强制暂停当前播放音频
  50. * @method stepPlay(count) 快进快退
  51. * @method syncStateOn(action, cb) 注册一个用于同步获取当前播放状态的事件
  52. * @method syncStateOff(action) 卸载用于同步获取当前播放状态的事件
  53. *
  54. *
  55. * **/
  56. export default class ZAudio extends EventBus {
  57. static version: string;
  58. loading: boolean;
  59. renderIndex: number;
  60. audiolist: Array<audio>;
  61. renderinfo: audioInfo;
  62. playinfo: audioInfo;
  63. paused: boolean;
  64. uPause: boolean;
  65. audioCtx: any;
  66. autoPlay: boolean;
  67. defaultCover: string;
  68. continuePlay: boolean;
  69. constructor(options: {
  70. defaultCover: string;
  71. autoPlay: boolean;
  72. continuePlay: boolean;
  73. });
  74. private init;
  75. checkEventParams(event: zaudioCbName, action: string | symbol, fn?: () => {}): boolean;
  76. /**
  77. * @description 回调中卸载业务事件
  78. * @param {<zaudioCbName>} event 回调名称枚举值
  79. * @param {Sting|Symbol} action 业务函数名,用于区分不同业务
  80. * @returns undefined
  81. * **/
  82. off(event: zaudioCbName, action: string | symbol): void;
  83. /**
  84. * @description 回调中注册业务事件
  85. * @param {<zaudioCbName>} event 回调名称枚举值
  86. * @param {Sting|Symbol} action 业务函数名,用于区分不同业务
  87. * @param {function(object|string|number|undefined):undefined} fn 业务函数, 参数或为音频状态
  88. * @returns undefined
  89. * **/
  90. on(event: zaudioCbName, action: string | symbol, fn: () => {}): void;
  91. /**
  92. * @description 订阅触发音频回调
  93. * @param {<zaudioCbName>} event 回调名称枚举值,具体看zaudioCbName
  94. * @param {object|string|number|undefined} data 订阅触发回调时,传的音频属性
  95. * @returns undefined
  96. * **/
  97. emit(event: zaudioCbName, data?: any): void;
  98. private commit;
  99. private onWaitingHandler;
  100. private onCanplayHandler;
  101. private onPlayHandler;
  102. private onPauseHandler;
  103. private onStopHandler;
  104. private onEndedHandler;
  105. private throttlePlaying;
  106. private onTimeUpdateHandler;
  107. private onErrorHandler;
  108. /**
  109. * @description 实时渲染当前状态
  110. * @returns undefined
  111. * **/
  112. syncRender(): void;
  113. /**
  114. * @description 注册一个实时获取ZAudio属性的方法
  115. * @param {String} action 自定义业务名
  116. * @param {Funtion} fn 实时获取ZAudio属性回调
  117. * @returns undefined
  118. * **/
  119. syncStateOn(action: string, fn: () => {}): void;
  120. /**
  121. * @description 卸载实时获取ZAudio属性的方法
  122. * @param {String} action 自定义业务名
  123. * @returns undefined
  124. * **/
  125. syncStateOff(action: string): void;
  126. /**
  127. * @description 订阅实时获取ZAudio属性的方法
  128. * @returns undefined
  129. * **/
  130. private syncStateEmit;
  131. /**
  132. * @description 跳转播放
  133. * @param {Number} value 跳转位置
  134. * @returns undefined
  135. * **/
  136. seek(value: number): void;
  137. /**
  138. * @description 快进
  139. * @param {Number} value 跳转位置
  140. * @returns undefined
  141. * **/
  142. stepPlay(value: number): void;
  143. /**
  144. * @description 获取下一首歌曲索引(用于渲染和播放)
  145. * @param {Number} count 切换数量
  146. * @returns number
  147. * **/
  148. private getNextKey;
  149. /**
  150. * @description 切歌
  151. * @param {Number} count 数量
  152. * @returns undefined
  153. * **/
  154. changeplay(count: number): void;
  155. /**
  156. * @description 手动播放或暂停, 并渲染对应的数据
  157. * @param {Number|String|<audioInfo>|undefined} key 索引或音频对象
  158. * @returns undefined
  159. * **/
  160. operate(key?: number | string | audioInfo): void;
  161. /**
  162. * @description 强制暂停播放
  163. * @returns undefined
  164. * **/
  165. stop(): void;
  166. private operation;
  167. /**
  168. * @description 覆盖音频
  169. * @param {Array<audio>} data 音频数组
  170. * @returns undefined
  171. * **/
  172. setAudio(data: Array<audio>): void;
  173. /**
  174. * @description 添加音频
  175. * @param {Array<audio>} data 音频数组
  176. * @returns undefined
  177. * **/
  178. updateAudio(data: Array<audio>): void;
  179. /**
  180. * @description 设置当前播放信息
  181. * @param {<audioInfo>} data 音频对象
  182. * @returns undefined
  183. * **/
  184. setPlayinfo<T extends keyof audioInfo>(data: audioInfo): void;
  185. /**
  186. * @description 设置暂停状态
  187. * @param {boolean} data 布尔值
  188. * @returns undefined
  189. * **/
  190. setPause(data: boolean): void;
  191. /**
  192. * @description 设置loading
  193. * @param {boolean} data 布尔值
  194. * @returns undefined
  195. * **/
  196. setLoading(data: boolean): void;
  197. /**
  198. * @description 设置通话时暂停状态
  199. * @param {boolean} data 布尔值
  200. * @returns undefined
  201. * **/
  202. setUnnormalPause(data: boolean): void;
  203. /**
  204. * @description 设置渲染
  205. * @param {number | string | audioInfo} data 索引或渲染信息
  206. * @returns undefined
  207. * **/
  208. setRender(data: number | string | audioInfo): void;
  209. get playIndex(): number;
  210. get renderIsPlay(): boolean;
  211. private appCheckReplay;
  212. }
  213. export {};