1ae784e_part_12_SoundCloudPlayer_4.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. function SoundCloudPlayer(ref_id, object_for_player, finish_callback, autoplay)
  2. {
  3. autoplay = typeof autoplay !== 'undefined' ? autoplay : false;
  4. var _autoplay = autoplay;
  5. var _iframe_id = '';
  6. if (typeof(ref_id) == 'string')
  7. {
  8. var _ref_id = ref_id.replace('http://', 'https://');
  9. }
  10. else
  11. {
  12. var _ref_id = ref_id
  13. }
  14. var _object_for_player = object_for_player;
  15. var _player = null;
  16. var _sounds_count = 0;
  17. var _current_sound_index = 0;
  18. var _finish_callback = finish_callback;
  19. this.play = function(play_callback)
  20. {
  21. var event_play_callback = function() {
  22. event_play();
  23. play_callback();
  24. }
  25. createPlayer(
  26. event_ready,
  27. event_play_callback,
  28. event_finish
  29. );
  30. }
  31. var createPlayer = function(callback_ready, callback_play, callback_finish)
  32. {
  33. _iframe_id = 'soundcloud_player_'+new Date().getTime();
  34. if (!_autoplay)
  35. {
  36. _object_for_player.html('<iframe id="'+_iframe_id+'" src="https://w.soundcloud.com/player/?url='
  37. +_ref_id+'&show_artwork=false&auto_play=true" width="100%" '
  38. +'height="350" scrolling="no" frameborder="no"></iframe>');
  39. }
  40. else
  41. {
  42. $('#autoplay_player_soundcloud').append('<iframe id="'+_iframe_id+'" src="https://w.soundcloud.com/player/?url='
  43. +_ref_id+'&show_artwork=false&auto_play=true" width="100%" '
  44. +'height="350" scrolling="no" frameborder="no"></iframe>');
  45. }
  46. SC.initialize({
  47. client_id: '39946ea18e3d78d64c0ac95a025794e1'
  48. });
  49. SC.get(_ref_id, function(track, error)
  50. {
  51. if (!error)
  52. {
  53. _player = SC.Widget(document.getElementById(_iframe_id));
  54. _player.bind(SC.Widget.Events.READY, callback_ready);
  55. _player.bind(SC.Widget.Events.PLAY, callback_play);
  56. _player.bind(SC.Widget.Events.FINISH, callback_finish);
  57. }
  58. else
  59. {
  60. _finish_callback();
  61. }
  62. });
  63. }
  64. var event_ready = function()
  65. {
  66. _player.getSounds(function(value){
  67. _sounds_count = value.length;
  68. });
  69. }
  70. var event_play = function()
  71. {
  72. _player.getSounds(function(value){
  73. _sounds_count = value.length;
  74. });
  75. _player.getCurrentSoundIndex(function(value){
  76. _current_sound_index = value;
  77. });
  78. }
  79. var event_finish = function()
  80. {
  81. if (_sounds_count == _current_sound_index+1)
  82. {
  83. event_finish_playlist();
  84. }
  85. }
  86. var event_finish_playlist = function()
  87. {
  88. _finish_callback();
  89. }
  90. this.stop = function()
  91. {
  92. }
  93. this.destroy = function(force)
  94. {
  95. if (_player && !_autoplay)
  96. {
  97. _object_for_player.html('');
  98. }
  99. if (_autoplay || force)
  100. {
  101. $('#autoplay_player_soundcloud').html('');
  102. }
  103. }
  104. this.stopAndDestroy = function()
  105. {
  106. //this.stop();
  107. this.destroy(false);
  108. }
  109. this.close = function()
  110. {
  111. this.destroy(true);
  112. }
  113. this.enableFullScreen = function() {
  114. }
  115. this.disableFullScreen = function() {
  116. }
  117. }