f792d24_part_12_GenericStreamingPlayer_2.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. function GenericStreamingPlayer(ref_id, object_for_player,
  2. callback_event_play,
  3. callback_event_end,
  4. callback_event_error,
  5. callback_event_finish_playlist
  6. )
  7. {
  8. var _ref_id = ref_id;
  9. var _object_for_player = object_for_player;
  10. var _playlist = new Array();
  11. var _player = null;
  12. var _player_dom = null;
  13. var _callback_event_play = callback_event_play;
  14. var _callback_event_end = callback_event_end;
  15. var _callback_event_error = callback_event_error;
  16. var _callback_event_finish_playlist = callback_event_finish_playlist;
  17. var _current_index = 0;
  18. this.create_player = function()
  19. {
  20. var jplayer_player = $('#jquery_jplayer_1').clone();
  21. var jplayer_content = $('#jp_container_1').clone();
  22. jplayer_player.attr ('id', 'jplayer_player_element_'+ref_id);
  23. jplayer_content.attr('id', 'jplayer_content_element_'+ref_id);
  24. _object_for_player.html('');
  25. _object_for_player.append(jplayer_player);
  26. _object_for_player.append(jplayer_content);
  27. JQueryJson(url_element_get_stream_data+'/'+ref_id, {}, function(response){
  28. if (response.status == 'success')
  29. {
  30. if (response.data)
  31. {
  32. for(var i = 0; i < response.data.length; i++)
  33. {
  34. var song = new GenericSong(response.data[i].name, response.data[i].url);
  35. _playlist[i] = song;
  36. }
  37. _player = new jPlayerPlaylist
  38. (
  39. {
  40. jPlayer: '#jplayer_player_element_'+ref_id,
  41. cssSelectorAncestor: '#jplayer_content_element_'+ref_id
  42. },
  43. _playlist,
  44. {
  45. playlistOptions:
  46. {
  47. autoPlay: true,
  48. enableRemoveControls: true
  49. },
  50. swfPath: "/jplayer/js",
  51. supplied: "mp3",
  52. wmode: "window"
  53. }
  54. );
  55. var _player_dom = $('#jplayer_player_element_'+ref_id);
  56. _player_dom.bind($.jPlayer.event.play, event_play);
  57. _player_dom.bind($.jPlayer.event.ended, event_end);
  58. _player_dom.bind($.jPlayer.event.error, event_error);
  59. }
  60. else
  61. {
  62. _callback_event_finish_playlist();
  63. }
  64. }
  65. else
  66. {
  67. _callback_event_finish_playlist();
  68. }
  69. });
  70. }
  71. var event_play = function(event)
  72. {
  73. _current_index = _player.current;
  74. _callback_event_play(event);
  75. }
  76. var event_end = function(event)
  77. {
  78. _callback_event_end(event);
  79. if (_current_index+1 == _playlist.length)
  80. {
  81. event_finish_playlist(event);
  82. }
  83. }
  84. var event_error = function(event)
  85. {
  86. _callback_event_error(event);
  87. }
  88. var event_finish_playlist = function(event)
  89. {
  90. _callback_event_finish_playlist(event);
  91. }
  92. this.play = function()
  93. {
  94. _player_dom.jPlayer("play");
  95. }
  96. this.stop = function()
  97. {
  98. //_player_dom.jPlayer("stop");
  99. }
  100. this.pause = function()
  101. {
  102. _player_dom.jPlayer("pause");
  103. }
  104. this.destroy = function()
  105. {
  106. _object_for_player.html('');
  107. }
  108. }
  109. function GenericSong(title, mp3)
  110. {
  111. this.title = title;
  112. this.mp3 = mp3;
  113. }