Station.vue 11 KB

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