ezVideo.service.ts 709 B

123456789101112131415161718192021222324252627
  1. import EZUIKit from 'ezuikit-js'
  2. export default class EzVideoService {
  3. player = null as unknown as EZUIKit.EZUIKitPlayer | null
  4. init(option: EZUIKit.EZUIKitPlayerOptions, callBack?: (e: any) => void) {
  5. if (this.player) this.destory()
  6. this.player = new EZUIKit.EZUIKitPlayer({
  7. ...option,
  8. template: 'simple',
  9. handleError: (err) => {
  10. console.error('handleError', err)
  11. if (callBack) callBack(err)
  12. },
  13. handleSuccess: (res) => {
  14. console.info('handleSuccess', res)
  15. if (callBack) callBack(res)
  16. }
  17. })
  18. this.player.play()
  19. return this.player
  20. }
  21. destory() {
  22. if (this.player) this.player.stop()
  23. this.player = null
  24. }
  25. }