StationBody.Vue 9.2 KB

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