Station.vue 9.4 KB

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