_Video.cshtml 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. @using WeApp.Helpers
  2. @{
  3. string id = "scene-play";
  4. string playIcon = "<div class=\"play-icon\"><i class=\"fas fa-play\"></i></div>";
  5. string playDiv = $"<div class=\"media-box\">{playIcon}</div>";
  6. }
  7. <style>
  8. </style>
  9. @Html.Partial("__/_AreaBox", $"情景视频#{id}#{playDiv}")
  10. @using (Html.BeginScripts())
  11. {
  12. <script id="attach-script">
  13. var attach_play_timer;
  14. var imageTemplate = '<img src="{0}" style="width: 100%;height: 100%;" />',//muted
  15. videoTemplate = '<video id="video" style="width: 100%;height: 100%;" controls muted autoplay><source src="{0}" type="video/mp4">您的浏览器不支持 HTML5 video 标签。</video>',
  16. audioTemplate = '<audio id="video" style="width: 100%;height: 100%;" controls muted autoplay><source src="{0}" type="audio/mp3">您的浏览器不支持 HTML5 audio 标签。</audio>';
  17. var $playBox = $('#@id .media-box');
  18. window.Scroll2Bottom($('#@id').find('.scroll-box'));
  19. function PlayNext() {
  20. if (window.isPlaying) {
  21. return;
  22. }
  23. $(".attach").removeClass("playing");
  24. if (window.waitToPlayAttachList && window.waitToPlayAttachList.length) {
  25. var nextAttach = window.waitToPlayAttachList.shift();
  26. if (nextAttach) {
  27. Play(nextAttach.filePath, nextAttach.fileType, nextAttach.attachNo);
  28. }
  29. } else {
  30. $playBox.fadeOut(300,
  31. () => {
  32. $playBox.html('@Html.Raw(playIcon)').fadeIn();
  33. });
  34. }
  35. }
  36. function Play(path, type, no) {
  37. @*@if (IwbConsts.IsDebug){
  38. <text>
  39. path = "http://shvber.com:5028/" + path;
  40. </text>
  41. }*@
  42. if (type) {
  43. window.isPlaying = true;
  44. //var str = type === "image"
  45. // ? imageTemplate.format(path)
  46. // : type === "video"
  47. // ? videoTemplate.format(path)
  48. // : type === "audio"
  49. // ? audioTemplate.format(path)
  50. // : '';
  51. if (type == "image") {
  52. var str = imageTemplate.format(path);
  53. $playBox.fadeOut(300,
  54. () => {
  55. $playBox.html(str).fadeIn();
  56. clearTimeout(attach_play_timer);
  57. attach_play_timer = setTimeout(() => {
  58. window.isPlaying = false;
  59. PlayNext();
  60. },
  61. 1000 * 15);
  62. });
  63. } else if (type === "video" || type === "audio") {
  64. $playBox.fadeOut(300,
  65. () => {
  66. var video = document.createElement("video");
  67. var hasLoad = false;
  68. video.loop = false;
  69. //video.muted = true;
  70. video.controls = true;
  71. video.src = path;
  72. video.style.width = '100%';
  73. video.style.height = '100%';
  74. video.addEventListener("loadstart", () => { hasLoad = false; },false);
  75. video.addEventListener('durationchange', () => { hasLoad = true; },false);
  76. video.addEventListener('ended', () => { setTimeout(function () { window.isPlaying = false; PlayNext(); }, 1000 * 0.5); }, false);
  77. setTimeout(() => { if (!hasLoad) { window.isPlaying = false; PlayNext(); } }, 1000 * 3);
  78. $playBox.html(video).fadeIn();
  79. video.play();
  80. });
  81. }
  82. $(".attach").removeClass("playing");
  83. if (no) {
  84. $("#" + no).addClass('playing');
  85. }
  86. //$playBox.fadeOut(300,
  87. // () => {
  88. // $playBox.html(str).fadeIn();
  89. // if (type === "video") {
  90. // var video = document.getElementById("video");
  91. // if (video) {
  92. // try {
  93. // var hasLoad = false;
  94. // video.loop = false;
  95. // video.addEventListener("loadstart", () => { hasLoad = false; },false);
  96. // video.addEventListener('durationchange', () => { hasLoad = true; },false);
  97. // video.addEventListener('ended', () => {
  98. // setTimeout(function() {window.isPlaying = false;PlayNext();},
  99. // 1000 * 0.5);
  100. // },
  101. // false);
  102. // setTimeout(() => {
  103. // if (!hasLoad) {
  104. // window.isPlaying = false; PlayNext();
  105. // }
  106. // }, 1000 * 3);
  107. // //video.play();
  108. // //setTimeout(() => {video.pause();video.load();},10);
  109. // } catch (e) {
  110. // console.log(e);
  111. // setTimeout(() => {window.isPlaying = false;PlayNext();},1000 * 0.5);
  112. // }
  113. // } else {
  114. // setTimeout(() => {window.isPlaying = false;PlayNext();},1000 * 0.5);
  115. // }
  116. // } else if (type === "image") {
  117. // clearTimeout(attach_play_timer);
  118. // attach_play_timer = setTimeout(() => {window.isPlaying = false;PlayNext();},1000 * 15);
  119. // }else if (type === "video") {
  120. // }
  121. // });
  122. }
  123. }
  124. function PlayLoop(url, type) {
  125. type = type || "video";
  126. $playBox.fadeOut(300,
  127. () => {
  128. var video = document.createElement(type);
  129. video.loop = true;
  130. //video.muted = true;
  131. video.controls = true;
  132. video.src = url;
  133. video.style.width = '100%';
  134. video.style.height = '100%';
  135. $playBox.html(video).fadeIn();
  136. video.play();
  137. });
  138. }
  139. </script>
  140. }