videoControl.js 892 B

123456789101112131415161718192021222324252627282930313233
  1. import $ from 'jquery';
  2. // 播放当前视频时停止其他视频播放
  3. const stopOtherVideo = function () {
  4. $(document).ready(function () {
  5. let videos = $('video');
  6. function pauseAll() {
  7. let self = this;
  8. ;[].forEach.call(videos, i => {
  9. // 将 videos 中其他的 video 全部暂停
  10. i !== self && i.pause();
  11. // i !== self && i.load();
  12. });
  13. };
  14. // 给play事件绑定暂停函数
  15. ;[].forEach.call(videos, i => {
  16. i.addEventListener('play', pauseAll.bind(i))
  17. });
  18. });
  19. };
  20. // 关闭所有视频
  21. const closeAllVideoFun = function () {
  22. let videos = $('video');
  23. let videosArr = Array.prototype.slice.call(videos);
  24. videosArr.forEach(x => {
  25. x.pause();
  26. // x.load();
  27. });
  28. };
  29. export { stopOtherVideo, closeAllVideoFun }