QueueSongs.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <div class='columns is-mobile'>
  3. <div class='column is-8-desktop is-offset-2-desktop is-12-mobile'>
  4. <table class='table is-striped'>
  5. <thead>
  6. <tr>
  7. <td>Title</td>
  8. <td>YouTube ID</td>
  9. <td>Artists</td>
  10. <td>Genres</td>
  11. <td>Options</td>
  12. </tr>
  13. </thead>
  14. <tbody>
  15. <tr v-for='(index, song) in songs' track-by='$index'>
  16. <td>
  17. <p class='control'>
  18. <input class='input' type='text' v-model='song.title'>
  19. </p>
  20. </td>
  21. <td>
  22. <p class='control'>
  23. <input class='input' type='text' v-model='song._id'>
  24. </p>
  25. </td>
  26. <td>
  27. <div class='control'>
  28. <input v-for='artist in song.artists' track-by='$index' class='input' type='text' v-model='artist'>
  29. </div>
  30. </td>
  31. <td>
  32. <div class='control'>
  33. <input v-for='genre in song.genres' track-by='$index' class='input' type='text' v-model='genre'>
  34. </div>
  35. </td>
  36. <td>
  37. <a class='button is-primary' @click='edit(song, index)'>Edit</a>
  38. <a class='button is-success' @click='add(song)'>Add</a>
  39. <a class='button is-danger' @click='remove(song._id, index)'>Remove</a>
  40. </td>
  41. </tr>
  42. </tbody>
  43. </table>
  44. </div>
  45. </div>
  46. <div class='modal' :class="{ 'is-active': isEditActive }">
  47. <div class='modal-background'></div>
  48. <div class='modal-card'>
  49. <section class='modal-card-body'>
  50. <h5 class='has-text-centered'>Video Preview</h5>
  51. <div class='video-container'>
  52. <div id='player'></div>
  53. <p class='control has-addons'>
  54. <a class='button'>
  55. <i class='material-icons' @click='pauseVideo()' v-if='!video.paused'>pause</i>
  56. <i class='material-icons' @click='playVideo()' v-else>play_arrow</i>
  57. </a>
  58. <a class='button' @click='stopVideo()'>
  59. <i class='material-icons'>stop</i>
  60. </a>
  61. <a class='button' @click='skipToLast10Secs()'>
  62. <i class='material-icons'>fast_forward</i>
  63. </a>
  64. </p>
  65. </div>
  66. <h5 class='has-text-centered'>Thumbnail Preview</h5>
  67. <img class='thumbnail-preview' :src='editing.song.thumbnail'>
  68. <label class='label'>Thumbnail URL</label>
  69. <p class='control'>
  70. <input class='input' type='text' v-model='editing.song.thumbnail'>
  71. </p>
  72. <h5 class='has-text-centered'>Edit Info</h5>
  73. <label class='label'>Song ID</label>
  74. <p class='control'>
  75. <input class='input' type='text' v-model='editing.song._id'>
  76. </p>
  77. <label class='label'>Song Title</label>
  78. <p class='control'>
  79. <input class='input' type='text' v-model='editing.song.title'>
  80. </p>
  81. <label class='label'>Artists</label>
  82. <div class='control'>
  83. <input v-for='artist in editing.song.artists' track-by='$index' class='input' type='text' v-model='artist'>
  84. </div>
  85. <label class='label'>Genres</label>
  86. <div class='control'>
  87. <input v-for='genre in editing.song.genres' track-by='$index' class='input' type='text' v-model='genre'>
  88. </div>
  89. <label class='label'>Song Duration</label>
  90. <p class='control'>
  91. <input class='input' type='text' v-model='editing.song.duration'>
  92. </p>
  93. <label class='label'>Skip Duration</label>
  94. <p class='control'>
  95. <input class='input' type='text' v-model='editing.song.skipDuration'>
  96. </p>
  97. </section>
  98. <footer class='modal-card-foot'>
  99. <button class='delete' @click='toggleModal()'></button>
  100. </footer>
  101. </div>
  102. </div>
  103. </template>
  104. <script>
  105. import { Toast } from 'vue-roaster';
  106. export default {
  107. data() {
  108. return {
  109. songs: [],
  110. isEditActive: false,
  111. editing: {
  112. index: 0,
  113. song: {}
  114. },
  115. video: {
  116. player: null,
  117. paused: false
  118. }
  119. }
  120. },
  121. methods: {
  122. toggleModal: function () {
  123. this.isEditActive = !this.isEditActive;
  124. this.pauseVideo();
  125. },
  126. edit: function (song, index) {
  127. this.editing = { index, song };
  128. this.video.player.loadVideoById(song._id);
  129. this.isEditActive = true;
  130. },
  131. pauseVideo: function () {
  132. this.video.player.pauseVideo();
  133. this.video.paused = true;
  134. },
  135. playVideo: function () {
  136. this.video.player.playVideo();
  137. this.video.paused = false;
  138. },
  139. stopVideo: function () {
  140. this.video.player.stopVideo();
  141. this.video.paused = true;
  142. },
  143. skipToLast10Secs: function () {
  144. this.video.player.seekTo(this.video.player.getDuration() - 10);
  145. },
  146. add: function (song) {
  147. this.socket.emit('queueSongs.remove', song._id);
  148. this.socket.emit('songs.add', song, res => {
  149. if (res.status == 'success') Toast.methods.addToast(res.message, 2000);
  150. });
  151. },
  152. remove: function (id, index) {
  153. this.songs.splice(index, 1);
  154. this.socket.emit('queueSongs.remove', id, res => {
  155. if (res.status == 'success') Toast.methods.addToast(res.message, 2000);
  156. });
  157. }
  158. },
  159. ready: function () {
  160. let _this = this;
  161. let socketInterval = setInterval(() => {
  162. if (!!_this.$parent.$parent.socket) {
  163. _this.socket = _this.$parent.$parent.socket;
  164. _this.socket.emit('queueSongs.index', data => {
  165. _this.songs = data;
  166. });
  167. clearInterval(socketInterval);
  168. }
  169. }, 100);
  170. this.video.player = new YT.Player('player', {
  171. height: 315,
  172. width: 560,
  173. videoId: this.editing.song._id,
  174. playerVars: { controls: 1, iv_load_policy: 3, rel: 0, showinfo: 0 },
  175. events: {
  176. 'onStateChange': event => {
  177. if (event.data == 1) {
  178. let youtubeDuration = _this.video.player.getDuration();
  179. youtubeDuration -= _this.editing.song.skipDuration;
  180. if (_this.editing.song.duration > youtubeDuration) this.stopVideo();
  181. }
  182. }
  183. }
  184. });
  185. }
  186. }
  187. </script>
  188. <style lang='scss' scoped>
  189. body {
  190. font-family: 'Roboto', sans-serif;
  191. }
  192. .thumbnail-preview {
  193. display: flex;
  194. margin: 0 auto;
  195. padding: 10px 0 20px 0;
  196. }
  197. .modal-card-body, .modal-card-foot {
  198. border-top: 0;
  199. background-color: rgb(66, 165, 245);
  200. }
  201. .label, h5 {
  202. color: #fff;
  203. font-weight: normal;
  204. }
  205. .video-container {
  206. display: flex;
  207. flex-direction: column;
  208. align-items: center;
  209. padding: 10px;
  210. }
  211. </style>