index.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import 'babel-polyfill'
  2. import videoSource from './videoData.js'
  3. import Img2Video from './src/img2video.js'
  4. //格式数据
  5. let videoSourceCopy = []
  6. for (let key in videoSource) {
  7. let videos = videoSource[key]
  8. videoSourceCopy.push(...videos)
  9. }
  10. (() => {
  11. let loadedPercentEle = document.querySelector('#loadedPercent')
  12. let clickBtn = document.querySelector('#videoPlayBtn')
  13. let endClickBtn = document.querySelector('#videoEndBtn')
  14. let video = new Img2Video({
  15. el: "#img2video1",
  16. frames: videoSourceCopy,
  17. preload: 'none',
  18. preloaded: () => {
  19. console.log('video preloaded')
  20. },
  21. loadProgress: (percent) => {
  22. console.log('video loaded ' + percent + '%')
  23. loadedPercentEle.innerHTML = '进度:' + parseInt(percent)
  24. },
  25. timeUpdate: (frame) => {
  26. console.log(this, frame)
  27. if (frame == 9 || frame == 30 || frame == 159) {
  28. clickBtn.style.display = 'block'
  29. video.pause()
  30. }
  31. },
  32. play: () => {
  33. console.log('video play')
  34. },
  35. end: () => {
  36. console.log('video ended')
  37. endClickBtn.style.display = 'block'
  38. }
  39. })
  40. video.start()
  41. clickBtn.addEventListener('click', () => {
  42. clickBtn.style.display = 'none'
  43. video.start()
  44. })
  45. endClickBtn.addEventListener('click', () => {
  46. endClickBtn.style.display = 'none'
  47. video.frame = 0
  48. video.start()
  49. })
  50. })();