Station.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. <template>
  2. <station-header></station-header>
  3. <div class="station">
  4. <div class="row">
  5. <div class="col-md-8 col-md-push-2 col-sm-10 col-sm-push-1 col-xs-12 video-col">
  6. <div class="video-container">
  7. <div id="player"></div>
  8. <!--iframe id="player" frameborder="0" allowfullscreen="1" title="YouTube video player" width="480" height="270" src="https://www.youtube.com/embed/xo1VInw-SKc?controls=0&amp;iv_load_policy=3&amp;rel=0&amp;showinfo=0&amp;enablejsapi=1&amp;origin=https%3A%2F%2Fmusare.com&amp;widgetid=1" kwframeid="1"></iframe-->
  9. </div>
  10. </div>
  11. <div class="col-md-8 col-md-push-2 col-sm-10 col-sm-push-1 col-xs-12">
  12. <div class="row">
  13. <button v-if="paused" @click="unpauseStation()">Unpause</button>
  14. <button v-if="!paused" @click="pauseStation()">Pause</button>
  15. <div class="col-md-8 col-sm-12 col-sm-12">
  16. <h4 id="time-display">{{timeElapsed}} / {{songDuration}}</h4>
  17. <h3>{{title}}</h3>
  18. <h4 class="thin" style="margin-left: 0">{{artists}}</h4>
  19. <div class="row">
  20. <form style="margin-top: 12px; margin-bottom: 0;" action="#" class="col-md-4 col-lg-4 col-xs-4 col-sm-4">
  21. <p style="margin-top: 0; position: relative;">
  22. <input type="range" id="volumeSlider" min="0" max="100" class="active" v-on:change="changeVolume()" v-on:input="changeVolume()">
  23. </p>
  24. </form>
  25. <div class="col-xs-8 col-sm-5 col-md-5" style="float: right;">
  26. <ul id="ratings">
  27. <li id="like" class="right"><span class="flow-text">{{likes}} </span> <i id="thumbs_up" class="material-icons grey-text" @click="toggleLike()">thumb_up</i></li>
  28. <li style="margin-right: 10px;" id="dislike" class="right"><span class="flow-text">{{dislikes}} </span><i id="thumbs_down" class="material-icons grey-text" @click="toggleDislike()">thumb_down</i></li>
  29. </ul>
  30. </div>
  31. </div>
  32. <div class="seeker-bar-container white" id="preview-progress">
  33. <div class="seeker-bar light-blue" style="width: 60.9869%;"></div>
  34. </div>
  35. </div>
  36. <img alt="Not loading" class="img-responsive col-md-4 col-xs-12 col-sm-12" onerror="this.src='../assets/notes.png'" id="song-image" style="margin-top: 10px !important" v-bind:src="image" />
  37. </div>
  38. </div>
  39. </div>
  40. </div>
  41. <main-footer></main-footer>
  42. </template>
  43. <script>
  44. import StationHeader from '../StationHeader.vue'
  45. import MainFooter from '../MainFooter.vue'
  46. export default {
  47. data() {
  48. return {
  49. playerReady: false,
  50. currentSong: undefined,
  51. player: undefined,
  52. timePaused: 0,
  53. paused: false,
  54. songDuration: "0:00",
  55. timeElapsed: "0:00",
  56. artists: "",
  57. title: "",
  58. image: "",
  59. likes: 0,
  60. dislikes: 0,
  61. interval: 0
  62. }
  63. },
  64. methods: {
  65. youtubeReady: function() {
  66. let local = this;
  67. local.player = new YT.Player("player", {
  68. height: 270,
  69. width: 480,
  70. videoId: local.currentSong.id,
  71. playerVars: {controls: 1, iv_load_policy: 3, rel: 0, showinfo: 0},
  72. events: {
  73. 'onReady': function (event) {
  74. local.playerReady = true;
  75. let volume = parseInt(localStorage.getItem("volume"));
  76. volume = (typeof volume === "number") ? volume : 20;
  77. local.player.setVolume(volume);
  78. if (volume > 0) {
  79. local.player.unMute();
  80. }
  81. local.playVideo();
  82. },
  83. 'onStateChange': function (event) {
  84. if (event.data === 1 && local.videoLoading === true) {
  85. local.videoLoading = false;
  86. local.player.seekTo(local.getTimeElapsed() / 1000, true);
  87. if (local.paused) {
  88. local.player.pauseVideo();
  89. }
  90. }
  91. }
  92. }
  93. });
  94. },
  95. startSong: function(song) {
  96. let local = this;
  97. if (local.playerReady) {
  98. }
  99. },
  100. getTimeElapsed: function() {
  101. let local = this;
  102. if (local.currentSong !== undefined) {
  103. return Date.now() - local.currentSong.startedAt - local.timePaused;
  104. }
  105. return 0;
  106. },
  107. pauseVideo: function() {
  108. let local = this;
  109. local.paused = true;
  110. if (local.playerReady) {
  111. local.player.pauseVideo();
  112. }
  113. },
  114. unpauseVideo: function() {
  115. let local = this;
  116. local.paused = false;
  117. if (local.playerReady) {
  118. local.player.seekTo(local.getTimeElapsed() / 1000);
  119. local.player.playVideo();
  120. }
  121. },
  122. playVideo: function() {
  123. let local = this;
  124. if (local.playerReady) {
  125. local.videoLoading = true;
  126. local.player.loadVideoById(local.currentSong.id);
  127. var d = moment.duration(parseInt(local.currentSong.duration), 'seconds');
  128. local.songDuration = d.minutes() + ":" + ("0" + d.seconds()).slice(-2);
  129. local.artists = local.currentSong.artists.join(", ");
  130. local.title = local.currentSong.title;
  131. local.image = local.currentSong.image;
  132. local.likes = local.currentSong.likes;
  133. local.dislikes = local.currentSong.dislikes;
  134. if (local.interval !== 0) {
  135. clearInterval(local.interval);
  136. }
  137. local.interval = setInterval(function () {
  138. local.resizeSeekerbar();
  139. local.calculateTimeElapsed();
  140. }, 250);
  141. }
  142. },
  143. resizeSeekerbar: function() {
  144. let local = this;
  145. if (!local.paused) {
  146. $(".seeker-bar").width(((local.getTimeElapsed() / 1000) / local.currentSong.duration * 100) + "%");
  147. }
  148. },
  149. calculateTimeElapsed: function() {
  150. let local = this;
  151. let currentTime = Date.now();
  152. if (local.timePausedCurrentTime !== undefined && local.paused) {
  153. local.timePaused += (Date.now() - local.timePausedCurrentTime);
  154. local.timePausedCurrentTime = undefined;
  155. }
  156. let duration = (Date.now() - local.currentSong.startedAt - local.timePaused) / 1000;
  157. let songDuration = local.currentSong.duration;
  158. if (songDuration <= duration) {
  159. local.player.pauseVideo();
  160. }
  161. let d = moment.duration(duration, 'seconds');
  162. console.log(duration, " ", local.timePaused);
  163. if ((!local.paused || local.timeElapsed === "0:00") && duration <= songDuration) {
  164. local.timeElapsed = d.minutes() + ":" + ("0" + d.seconds()).slice(-2);
  165. }
  166. },
  167. changeVolume: function() {
  168. let local = this;
  169. let volume = $("#volumeSlider").val();
  170. localStorage.setItem("volume", volume);
  171. if (local.playerReady) {
  172. local.player.setVolume(volume);
  173. if (volume > 0) {
  174. local.player.unMute();
  175. }
  176. }
  177. },
  178. unpauseStation: function() {
  179. console.log("UNPAUSE1");
  180. let local = this;
  181. local.stationSocket.emit("unpause");
  182. },
  183. pauseStation: function() {
  184. console.log("PAUSE1");
  185. let local = this;
  186. local.stationSocket.emit("pause");
  187. },
  188. toggleLike: function() {
  189. let local = this;
  190. local.stationSocket.emit("toggleLike");//TODO Add code here to see if this was a success or not
  191. },
  192. toggleDislike: function() {
  193. let local = this;
  194. local.stationSocket.emit("toggleDislike");//TODO Add code here to see if this was a success or not
  195. }
  196. },
  197. ready: function() {
  198. let local = this;
  199. window.onYouTubeIframeAPIReady = function() {
  200. local.youtubeReady();
  201. };
  202. let socket = this.$parent.socket;
  203. local.stationSocket = io.connect('http://dev.musare.com/edm');
  204. local.stationSocket.on("skippedSong", function(currentSong) {
  205. console.log("SKIPPED SONG");
  206. local.currentSong = currentSong;
  207. local.timePaused = 0;
  208. local.playVideo();
  209. });
  210. local.stationSocket.on("pause", function() {
  211. console.log("PAUSE");
  212. local.pauseVideo();
  213. });
  214. local.stationSocket.on("unpause", function(timePaused) {
  215. console.log("UNPAUSE");
  216. local.timePaused = timePaused;
  217. local.unpauseVideo();
  218. });
  219. let volume = parseInt(localStorage.getItem("volume"));
  220. volume = (typeof volume === "number") ? volume : 20;
  221. $("#volumeSlider").val(volume);
  222. // TODO: Remove this
  223. socket.emit("/stations/join/:id", "edm", function(data) {
  224. local.currentSong = data.data.currentSong;
  225. local.paused = data.data.paused;
  226. local.timePaused = data.data.timePaused;
  227. local.timePausedCurrentTime = data.data.currentTime;
  228. let tag = document.createElement('script');
  229. tag.src = "https://www.youtube.com/iframe_api";
  230. let firstScriptTag = document.getElementsByTagName('script')[0];
  231. firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
  232. });
  233. },
  234. components: { StationHeader, MainFooter }
  235. }
  236. </script>
  237. <style lang="sass">
  238. .station {
  239. flex: 1 0 auto;
  240. padding-top: 4.5vw;
  241. transition: all 0.1s;
  242. margin: 0 auto;
  243. max-width: 1280px;
  244. width: 90%;
  245. @media only screen and (min-width: 993px) {
  246. width: 70%;
  247. }
  248. @media only screen and (min-width: 601px) {
  249. width: 85%;
  250. }
  251. input[type=range] {
  252. -webkit-appearance: none;
  253. width: 100%;
  254. margin: 7.3px 0;
  255. }
  256. input[type=range]:focus {
  257. outline: none;
  258. }
  259. input[type=range]::-webkit-slider-runnable-track {
  260. width: 100%;
  261. height: 5.2px;
  262. cursor: pointer;
  263. box-shadow: 0;
  264. background: #c2c0c2;
  265. border-radius: 0;
  266. border: 0;
  267. }
  268. input[type=range]::-webkit-slider-thumb {
  269. box-shadow: 0;
  270. border: 0;
  271. height: 19px;
  272. width: 19px;
  273. border-radius: 15px;
  274. background: #03a9f4;
  275. cursor: pointer;
  276. -webkit-appearance: none;
  277. margin-top: -6.5px;
  278. }
  279. input[type=range]::-moz-range-track {
  280. width: 100%;
  281. height: 5.2px;
  282. cursor: pointer;
  283. box-shadow: 0;
  284. background: #c2c0c2;
  285. border-radius: 0;
  286. border: 0;
  287. }
  288. input[type=range]::-moz-range-thumb {
  289. box-shadow: 0;
  290. border: 0;
  291. height: 19px;
  292. width: 19px;
  293. border-radius: 15px;
  294. background: #03a9f4;
  295. cursor: pointer;
  296. -webkit-appearance: none;
  297. margin-top: -6.5px;
  298. }
  299. input[type=range]::-ms-track {
  300. width: 100%;
  301. height: 5.2px;
  302. cursor: pointer;
  303. box-shadow: 0;
  304. background: #c2c0c2;
  305. border-radius: 1.3px;
  306. }
  307. input[type=range]::-ms-fill-lower {
  308. background: #c2c0c2;
  309. border: 0;
  310. border-radius: 0;
  311. box-shadow: 0;
  312. }
  313. input[type=range]::-ms-fill-upper {
  314. background: #c2c0c2;
  315. border: 0;
  316. border-radius: 0;
  317. box-shadow: 0;
  318. }
  319. input[type=range]::-ms-thumb {
  320. box-shadow: 0;
  321. border: 0;
  322. height: 15px;
  323. width: 15px;
  324. border-radius: 15px;
  325. background: #03a9f4;
  326. cursor: pointer;
  327. -webkit-appearance: none;
  328. margin-top: 1.5px;
  329. }
  330. .video-container {
  331. position: relative;
  332. padding-bottom: 56.25%;
  333. height: 0;
  334. overflow: hidden;
  335. iframe {
  336. position: absolute;
  337. top: 0;
  338. left: 0;
  339. width: 100%;
  340. height: 100%;
  341. pointer-events: none;
  342. }
  343. }
  344. .video-col {
  345. padding-right: 0.75rem;
  346. padding-left: 0.75rem;
  347. }
  348. }
  349. .room-title {
  350. left: 50%;
  351. -webkit-transform: translateX(-50%);
  352. transform: translateX(-50%);
  353. font-size: 2.1em;
  354. }
  355. #ratings {
  356. span {
  357. font-size: 1.68rem;
  358. }
  359. i {
  360. color: #9e9e9e !important;
  361. cursor: pointer;
  362. transition: 0.1s color;
  363. }
  364. }
  365. #time-display {
  366. margin-top: 30px;
  367. float: right;
  368. }
  369. #thumbs_up:hover {
  370. color: #87D37C !important;
  371. }
  372. #thumbs_down:hover {
  373. color: #EC644B !important;
  374. }
  375. .seeker-bar-container {
  376. position: relative;
  377. height: 5px;
  378. display: block;
  379. width: 100%;
  380. overflow: hidden;
  381. margin-top: 20px;
  382. }
  383. .seeker-bar {
  384. top: 0;
  385. left: 0;
  386. bottom: 0;
  387. position: absolute;
  388. }
  389. ul {
  390. list-style: none;
  391. margin: 0;
  392. display: block;
  393. }
  394. h1, h2, h3, h4, h5, h6 {
  395. font-weight: 400;
  396. line-height: 1.1;
  397. }
  398. h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {
  399. font-weight: inherit;
  400. }
  401. h1 {
  402. font-size: 4.2rem;
  403. line-height: 110%;
  404. margin: 2.1rem 0 1.68rem 0;
  405. }
  406. h2 {
  407. font-size: 3.56rem;
  408. line-height: 110%;
  409. margin: 1.78rem 0 1.424rem 0;
  410. }
  411. h3 {
  412. font-size: 2.92rem;
  413. line-height: 110%;
  414. margin: 1.46rem 0 1.168rem 0;
  415. }
  416. h4 {
  417. font-size: 2.28rem;
  418. line-height: 110%;
  419. margin: 1.14rem 0 0.912rem 0;
  420. }
  421. h5 {
  422. font-size: 1.64rem;
  423. line-height: 110%;
  424. margin: 0.82rem 0 0.656rem 0;
  425. }
  426. h6 {
  427. font-size: 1rem;
  428. line-height: 110%;
  429. margin: 0.5rem 0 0.4rem 0;
  430. }
  431. .thin {
  432. font-weight: 200;
  433. }
  434. .left {
  435. float: left !important;
  436. }
  437. .right {
  438. float: right !important;
  439. }
  440. .light-blue {
  441. background-color: #03a9f4 !important;
  442. }
  443. .white {
  444. background-color: #FFFFFF !important;
  445. }
  446. </style>