Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.39 KB | None | 0 0
  1. var currentId = null;
  2.  
  3. function timMixcloud(src){
  4.  
  5. console.log("var is " + currentId);
  6.  
  7. var audioStream = document.getElementById("player");
  8.  
  9. //auto prepei na paei sto document ready
  10.  
  11.  
  12.  
  13.  
  14.  
  15. // base64 encode src to get a unique id for the player (remove special char =)
  16. var id = btoa(src).replace(/=/gi,'');
  17.  
  18.  
  19.  
  20. // if clicked current playing mix, do nothing
  21. if (currentId === id) {
  22.  
  23. console.log("EDW DUSTUXWS" + currentId);
  24. const widget = Mixcloud.PlayerWidget(document.getElementById(currentId));
  25. widget.ready.then( () => {
  26. // ...pause
  27. widget.togglePlay();
  28. widget.events.pause.on(pauseListener);
  29. function pauseListener() {
  30.  
  31. console.log('is paused...')
  32. jQuery('span.icon-podcast').addClass('fa-play');
  33. jQuery('span.icon-podcast').removeClass('fa-pause');
  34.  
  35.  
  36. }
  37.  
  38. widget.events.play.on(playListener);
  39. function playListener() {
  40.  
  41. console.log('is playing...')
  42.  
  43. jQuery('span.icon-podcast').removeClass('fa-play rotating');
  44. jQuery('span.icon-podcast').addClass('fa-pause');
  45.  
  46. audioStream.pause();
  47.  
  48. jQuery('.play-icon').removeClass('invisible');
  49. jQuery('.stop-icon').addClass('invisible');
  50. jQuery('.radio-text').text('Tune Now');
  51. jQuery('.pulsate-css').addClass('invisible');
  52. }
  53.  
  54. widget.events.buffering.on(bufferingListener);
  55. function bufferingListener() {
  56.  
  57. console.log('is buffering...')
  58. jQuery('span.icon-podcast').removeClass('fa-play rotating');
  59. jQuery('span.icon-podcast').removeClass('fa-pause rotating');
  60. jQuery('span.icon-podcast').addClass('fa-refresh rotating ');
  61.  
  62.  
  63. }
  64. });
  65.  
  66. return;
  67. }
  68.  
  69.  
  70. // if something else is playing
  71. if (currentId !== null) {
  72. console.log("DEN THA EPREPE");
  73. // get access programmatically...
  74. const widget = Mixcloud.PlayerWidget(document.getElementById(currentId));
  75. widget.ready.then( () => {
  76. // ...pause
  77. widget.pause();
  78.  
  79. });
  80. // ...and hide
  81. jQuery(`#mixcloud-container #${currentId}`).remove();
  82.  
  83.  
  84.  
  85. }
  86.  
  87.  
  88.  
  89. // if player for new mix does not exist already
  90. if ( jQuery(`#mixcloud-container #${id}`).length === 0) {
  91.  
  92. console.log("EDW MPAINW");
  93. // create iframe
  94. const iframe = jQuery('<iframe>', {
  95. id: id,
  96. width: '100%',
  97. height: '60',
  98. src: `https://www.mixcloud.com/widget/iframe/?hide_cover=1&mini=1&dark=1&feed=${encodeURIComponent(src)}`,
  99. frameboder: 0
  100. });
  101.  
  102. // hide and append to footer
  103.  
  104. iframe.appendTo('#mixcloud-container');
  105.  
  106. const widget = Mixcloud.PlayerWidget(document.getElementById(id));
  107.  
  108.  
  109.  
  110.  
  111. jQuery(`#mixcloud-container #${id}`).show();
  112. jQuery(`.mixcloud-component`).show();
  113.  
  114. // now we sure the player exist
  115. // show the footer, change the current id to the new and play with programmatic api
  116.  
  117.  
  118. }
  119.  
  120.  
  121. currentId = id;
  122.  
  123. const widget = Mixcloud.PlayerWidget(document.getElementById(id));
  124. widget.ready.then( () => {
  125. // ...pause
  126. widget.play();
  127. });
  128.  
  129.  
  130.  
  131.  
  132. audioStream.pause();
  133.  
  134. jQuery('.play-icon').removeClass('invisible');
  135. jQuery('.stop-icon').addClass('invisible');
  136. jQuery('.radio-text').text('Tune Now');
  137. jQuery('.pulsate-css').addClass('invisible');
  138.  
  139.  
  140.  
  141.  
  142.  
  143. jQuery('.play-podcast-icon').addClass('invisible');
  144. jQuery('.pause-podcast-icon').removeClass('invisible');
  145. console.log(jQuery('iframe').attr('src'));
  146.  
  147.  
  148.  
  149.  
  150. }
  151.  
  152.  
  153. /*
  154.  
  155. jQuery('button#mixcloud-close-button').click( (e) => {
  156. jQuery(`#mixcloud-container #jQuery{currentId}`).remove();
  157. currentId = null;
  158. jQuery(`.mixcloud-component`).hide();
  159. jQuery('span.icon-podcast').addClass('fa-play');
  160. jQuery('span.icon-podcast').removeClass('fa-pause');
  161.  
  162.  
  163. });
  164. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement