_ScenePlay.cshtml 6.1 KB

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