_ScenePlay.cshtml 5.6 KB

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