xhrVideo.ts 753 B

1234567891011121314151617181920212223242526272829
  1. /**
  2. *
  3. * @param src 视频路径
  4. * @returns Promise - 视频的总长度
  5. */
  6. export const videoLodingNumFu = (src: string): Promise<number> => {
  7. return new Promise((resolve, reject) => {
  8. const req = new XMLHttpRequest()
  9. req.open('HEAD', src, true)
  10. req.onreadystatechange = function () {
  11. if (req.readyState === 4) {
  12. if (req.status === 200) {
  13. const contentLength = req.getResponseHeader('Content-Length')
  14. if (contentLength) {
  15. const videoLength = parseInt(contentLength, 10)
  16. resolve(videoLength)
  17. }
  18. }
  19. }
  20. }
  21. req.send()
  22. })
  23. }
  24. export const domDelOwnFu = (classNmae: string) => {
  25. const dom = document.querySelector(classNmae)
  26. if (dom) dom.remove()
  27. }