Station.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. <template>
  2. <station-header></station-header>
  3. <div class="station">
  4. <div class="columns is-mobile">
  5. <div class="column is-8-desktop is-offset-2-desktop is-12-mobile">
  6. <div class="video-container">
  7. <div id="player"></div>
  8. <div class="seeker-bar-container white" id="preview-progress">
  9. <div class="seeker-bar light-blue" style="width: 60.9869%;"></div>
  10. </div>
  11. </div>
  12. </div>
  13. </div>
  14. <div class="columns is-mobile">
  15. <div class="column is-8-desktop is-offset-2-desktop is-12-mobile">
  16. <!--<button v-if="paused" @click="unpauseStation()">Unpause</button>-->
  17. <!--<button v-if="!paused" @click="pauseStation()">Pause</button>-->
  18. <div class="columns is-mobile">
  19. <div class="column is-8-desktop is-12-mobile">
  20. <h4 id="time-display">{{timeElapsed}} / {{formatTime(currentSong.duration)}}</h4>
  21. <h3>{{currentSong.title}}</h3>
  22. <h4 class="thin" style="margin-left: 0">{{currentSong.artists}}</h4>
  23. <div class="columns is-mobile">
  24. <form style="margin-top: 12px; margin-bottom: 0;" action="#" class="column is-7-desktop is-4-mobile">
  25. <p style="margin-top: 0; position: relative;">
  26. <input type="range" id="volumeSlider" min="0" max="100" class="active" v-on:change="changeVolume()" v-on:input="changeVolume()">
  27. </p>
  28. </form>
  29. <div class="column is-8-mobile is-5-desktop" style="float: right;">
  30. <ul id="ratings">
  31. <li id="like" class="right"><span class="flow-text">{{currentSong.likes}} </span> <i id="thumbs_up" class="material-icons grey-text">thumb_up</i></li>
  32. <li style="margin-right: 10px;" id="dislike" class="right"><span class="flow-text">{{currentSong.dislikes}} </span><i id="thumbs_down" class="material-icons grey-text">thumb_down</i></li>
  33. </ul>
  34. </div>
  35. </div>
  36. </div>
  37. <button @click="addSongToQueue('aHjpOzsQ9YI')">ADD CRYSTALIZE!</button>
  38. <div class="column is-4-desktop is-12-mobile">
  39. <img class="image" id="song-thumbnail" style="margin-top: 10px !important" :src="currentSong.thumbnail" alt="Song Thumbnail" />
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. <div class="modal" :class="{ 'is-active': isActive }">
  46. <div class="modal-background"></div>
  47. <div class="modal-card">
  48. <header class="modal-card-head">
  49. <p class="modal-card-title">Add Songs to Station</p>
  50. <button class="delete" @click="toggleModal()" ></button>
  51. </header>
  52. <section class="modal-card-body">
  53. <div class="control is-grouped">
  54. <p class="control is-expanded">
  55. <input class="input" type="text" placeholder="YouTube Query" v-model="querySearch">
  56. </p>
  57. <p class="control">
  58. <a class="button is-info" @click="submitQuery()">
  59. Search
  60. </a>
  61. </p>
  62. </div>
  63. <table class="table">
  64. <tbody>
  65. <tr v-for="result in queryResults">
  66. <td>
  67. <img :src="result.thumbnail" />
  68. </td>
  69. <td>{{result.title}}</td>
  70. <td>
  71. <a class="button is-success" @click="addSongToQueue(result)">
  72. Add
  73. </a>
  74. </td>
  75. </tr>
  76. </tbody>
  77. </table>
  78. </section>
  79. </div>
  80. </div>
  81. </template>
  82. <script>
  83. import StationHeader from './StationHeader.vue';
  84. export default {
  85. data() {
  86. return {
  87. isActive: false,
  88. playerReady: false,
  89. currentSong: {},
  90. player: undefined,
  91. timePaused: 0,
  92. paused: false,
  93. timeElapsed: "0:00",
  94. interval: 0,
  95. querySearch: "",
  96. queryResults: [],
  97. queue: []
  98. }
  99. },
  100. methods: {
  101. toggleModal: function() {
  102. this.isActive = !this.isActive;
  103. },
  104. youtubeReady: function() {
  105. let local = this;
  106. console.log(123457)
  107. local.player = new YT.Player("player", {
  108. height: 270,
  109. width: 480,
  110. videoId: local.currentSong._id,
  111. playerVars: {controls: 1, iv_load_policy: 3, rel: 0, showinfo: 0},
  112. events: {
  113. 'onReady': function(event) {
  114. console.log(4540590459);
  115. local.playerReady = true;
  116. let volume = parseInt(localStorage.getItem("volume"));
  117. volume = (typeof volume === "number") ? volume : 20;
  118. local.player.setVolume(volume);
  119. if (volume > 0) {
  120. local.player.unMute();
  121. }
  122. local.playVideo();
  123. },
  124. 'onStateChange': function(event) {
  125. console.log(event);
  126. if (event.data === 1 && local.videoLoading === true) {
  127. local.videoLoading = false;
  128. local.player.seekTo(local.getTimeElapsed() / 1000, true);
  129. console.log(local.paused);
  130. if (local.paused) {
  131. local.player.pauseVideo();
  132. }
  133. }
  134. }
  135. }
  136. });
  137. },
  138. getTimeElapsed: function() {
  139. let local = this;
  140. if (local.currentSong) {
  141. return Date.now() - local.startedAt - local.timePaused;
  142. } else {
  143. return 0;
  144. }
  145. },
  146. playVideo: function() {
  147. let local = this;
  148. if (local.playerReady) {
  149. local.videoLoading = true;
  150. local.player.loadVideoById(local.currentSong._id);
  151. if (local.currentSong.artists) local.currentSong.artists = local.currentSong.artists.join(", ");
  152. if (local.interval !== 0) {
  153. clearInterval(local.interval);
  154. }
  155. local.interval = setInterval(function () {
  156. local.resizeSeekerbar();
  157. local.calculateTimeElapsed();
  158. }, 250);
  159. }
  160. },
  161. resizeSeekerbar: function() {
  162. let local = this;
  163. if (!local.paused) {
  164. $(".seeker-bar").width(parseInt(((local.getTimeElapsed() / 1000) / local.currentSong.duration * 100)) + "%");
  165. }
  166. },
  167. formatTime: function(duration) {
  168. let d = moment.duration(duration, 'seconds');
  169. return ((d.hours() > 0) ? (d.hours() < 10 ? ("0" + d.hours() + ":") : (d.hours() + ":")) : "") + (d.minutes() + ":") + (d.seconds() < 10 ? ("0" + d.seconds()) : d.seconds());
  170. },
  171. calculateTimeElapsed: function() {
  172. let local = this;
  173. let currentTime = Date.now();
  174. if (local.currentTime !== undefined && local.paused) {
  175. local.timePaused += (Date.now() - local.currentTime);
  176. local.currentTime = undefined;
  177. }
  178. let duration = (Date.now() - local.startedAt - local.timePaused) / 1000;
  179. let songDuration = local.currentSong.duration;
  180. if (songDuration <= duration) {
  181. console.log("PAUSE!");
  182. console.log(songDuration, duration);
  183. local.player.pauseVideo();
  184. }
  185. if ((!local.paused) && duration <= songDuration) {
  186. local.timeElapsed = local.formatTime(duration);
  187. }
  188. },
  189. changeVolume: function() {
  190. let local = this;
  191. let volume = $("#volumeSlider").val();
  192. localStorage.setItem("volume", volume);
  193. if (local.playerReady) {
  194. local.player.setVolume(volume);
  195. if (volume > 0) {
  196. local.player.unMute();
  197. }
  198. }
  199. },
  200. unpauseStation: function() {
  201. let local = this;
  202. local.paused = false;
  203. if (local.playerReady) {
  204. local.player.seekTo(local.getTimeElapsed() / 1000);
  205. local.player.playVideo();
  206. }
  207. },
  208. pauseStation: function() {
  209. let local = this;
  210. local.paused = true;
  211. if (local.playerReady) {
  212. local.player.pauseVideo();
  213. }
  214. },
  215. addSongToQueue: function(songId) {
  216. console.log('add', songId);
  217. let local = this;
  218. local.socket.emit('queueSongs.add', songId, function(data) {
  219. if (data) console.log(data);
  220. });
  221. }/*,
  222. submitQuery: function() {
  223. let local = this;
  224. local.socket.emit('apis.searchYoutube', local.querySearch, function(results) {
  225. results = results.data;
  226. local.queryResults = [];
  227. for (let i = 0; i < results.items.length; i++) {
  228. local.queryResults.push({
  229. id: results.items[i].id.videoId,
  230. url: `https://www.youtube.com/watch?v=${this.id}`,
  231. title: results.items[i].snippet.title,
  232. thumbnail: results.items[i].snippet.thumbnails.default.url
  233. });
  234. }
  235. });
  236. }*/
  237. },
  238. ready: function() {
  239. let _this = this;
  240. _this.stationId = _this.$route.params.id;
  241. _this.interval = 0;
  242. _this.socket = _this.$parent.socket;
  243. _this.socket.emit('stations.join', _this.stationId, data => {
  244. console.log(data);
  245. if (data.status === "success") {
  246. _this.currentSong = data.currentSong;
  247. _this.startedAt = data.startedAt;
  248. _this.paused = data.paused;
  249. _this.timePaused = data.timePaused;
  250. _this.youtubeReady();
  251. _this.playVideo();
  252. } else {
  253. //TODO Handle error
  254. }
  255. });
  256. _this.socket.on('event:songs.next', data => {
  257. console.log("NEXT SONG");
  258. _this.currentSong = data.currentSong;
  259. _this.startedAt = data.startedAt;
  260. _this.paused = data.paused;
  261. _this.timePaused = data.timePaused;
  262. _this.playVideo();
  263. });
  264. let volume = parseInt(localStorage.getItem("volume"));
  265. volume = (typeof volume === "number") ? volume : 20;
  266. $("#volumeSlider").val(volume);
  267. },
  268. components: { StationHeader }
  269. }
  270. </script>
  271. <style lang="scss">
  272. .modal-large {
  273. width: 75%;
  274. }
  275. .station {
  276. flex: 1 0 auto;
  277. padding-top: 0.5vw;
  278. transition: all 0.1s;
  279. margin: 0 auto;
  280. max-width: 1280px;
  281. width: 90%;
  282. @media only screen and (min-width: 993px) {
  283. width: 70%;
  284. }
  285. @media only screen and (min-width: 601px) {
  286. width: 85%;
  287. }
  288. input[type=range] {
  289. -webkit-appearance: none;
  290. width: 100%;
  291. margin: 7.3px 0;
  292. }
  293. input[type=range]:focus {
  294. outline: none;
  295. }
  296. input[type=range]::-webkit-slider-runnable-track {
  297. width: 100%;
  298. height: 5.2px;
  299. cursor: pointer;
  300. box-shadow: 0;
  301. background: #c2c0c2;
  302. border-radius: 0;
  303. border: 0;
  304. }
  305. input[type=range]::-webkit-slider-thumb {
  306. box-shadow: 0;
  307. border: 0;
  308. height: 19px;
  309. width: 19px;
  310. border-radius: 15px;
  311. background: #03a9f4;
  312. cursor: pointer;
  313. -webkit-appearance: none;
  314. margin-top: -6.5px;
  315. }
  316. input[type=range]::-moz-range-track {
  317. width: 100%;
  318. height: 5.2px;
  319. cursor: pointer;
  320. box-shadow: 0;
  321. background: #c2c0c2;
  322. border-radius: 0;
  323. border: 0;
  324. }
  325. input[type=range]::-moz-range-thumb {
  326. box-shadow: 0;
  327. border: 0;
  328. height: 19px;
  329. width: 19px;
  330. border-radius: 15px;
  331. background: #03a9f4;
  332. cursor: pointer;
  333. -webkit-appearance: none;
  334. margin-top: -6.5px;
  335. }
  336. input[type=range]::-ms-track {
  337. width: 100%;
  338. height: 5.2px;
  339. cursor: pointer;
  340. box-shadow: 0;
  341. background: #c2c0c2;
  342. border-radius: 1.3px;
  343. }
  344. input[type=range]::-ms-fill-lower {
  345. background: #c2c0c2;
  346. border: 0;
  347. border-radius: 0;
  348. box-shadow: 0;
  349. }
  350. input[type=range]::-ms-fill-upper {
  351. background: #c2c0c2;
  352. border: 0;
  353. border-radius: 0;
  354. box-shadow: 0;
  355. }
  356. input[type=range]::-ms-thumb {
  357. box-shadow: 0;
  358. border: 0;
  359. height: 15px;
  360. width: 15px;
  361. border-radius: 15px;
  362. background: #03a9f4;
  363. cursor: pointer;
  364. -webkit-appearance: none;
  365. margin-top: 1.5px;
  366. }
  367. .video-container {
  368. position: relative;
  369. padding-bottom: 56.25%;
  370. height: 0;
  371. overflow: hidden;
  372. iframe {
  373. position: absolute;
  374. top: 0;
  375. left: 0;
  376. width: 100%;
  377. height: 100%;
  378. /*pointer-events: none;*/
  379. }
  380. }
  381. .video-col {
  382. padding-right: 0.75rem;
  383. padding-left: 0.75rem;
  384. }
  385. }
  386. .room-title {
  387. left: 50%;
  388. -webkit-transform: translateX(-50%);
  389. transform: translateX(-50%);
  390. font-size: 2.1em;
  391. }
  392. #ratings {
  393. span {
  394. font-size: 1.68rem;
  395. }
  396. i {
  397. color: #9e9e9e !important;
  398. cursor: pointer;
  399. transition: 0.1s color;
  400. }
  401. }
  402. #time-display {
  403. margin-top: 30px;
  404. float: right;
  405. }
  406. #thumbs_up:hover {
  407. color: #87D37C !important;
  408. }
  409. #thumbs_down:hover {
  410. color: #EC644B !important;
  411. }
  412. #song-thumbnail {
  413. max-width: 100%;
  414. width: 85%;
  415. }
  416. .seeker-bar-container {
  417. position: relative;
  418. height: 5px;
  419. display: block;
  420. width: 100%;
  421. overflow: hidden;
  422. }
  423. .seeker-bar {
  424. top: 0;
  425. left: 0;
  426. bottom: 0;
  427. position: absolute;
  428. }
  429. ul {
  430. list-style: none;
  431. margin: 0;
  432. display: block;
  433. }
  434. h1, h2, h3, h4, h5, h6 {
  435. font-weight: 400;
  436. line-height: 1.1;
  437. }
  438. h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {
  439. font-weight: inherit;
  440. }
  441. h1 {
  442. font-size: 4.2rem;
  443. line-height: 110%;
  444. margin: 2.1rem 0 1.68rem 0;
  445. }
  446. h2 {
  447. font-size: 3.56rem;
  448. line-height: 110%;
  449. margin: 1.78rem 0 1.424rem 0;
  450. }
  451. h3 {
  452. font-size: 2.92rem;
  453. line-height: 110%;
  454. margin: 1.46rem 0 1.168rem 0;
  455. }
  456. h4 {
  457. font-size: 2.28rem;
  458. line-height: 110%;
  459. margin: 1.14rem 0 0.912rem 0;
  460. }
  461. h5 {
  462. font-size: 1.64rem;
  463. line-height: 110%;
  464. margin: 0.82rem 0 0.656rem 0;
  465. }
  466. h6 {
  467. font-size: 1rem;
  468. line-height: 110%;
  469. margin: 0.5rem 0 0.4rem 0;
  470. }
  471. .thin {
  472. font-weight: 200;
  473. }
  474. .left {
  475. float: left !important;
  476. }
  477. .right {
  478. float: right !important;
  479. }
  480. .light-blue {
  481. background-color: #03a9f4 !important;
  482. }
  483. .white {
  484. background-color: #FFFFFF !important;
  485. }
  486. .btn-search {
  487. font-size: 14px;
  488. }
  489. </style>