1ae784e_part_12_GenericStreamingPlayer_2.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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(play_callback)
  19. {
  20. var jplayer_player = $('#jquery_jplayer_1').clone();
  21. var jplayer_content = $('#jp_container_1').clone();
  22. var event_play_callback = function(event) {
  23. event_play(event);
  24. play_callback();
  25. };
  26. jplayer_player.attr ('id', 'jplayer_player_element_'+ref_id);
  27. jplayer_content.attr('id', 'jplayer_content_element_'+ref_id);
  28. _object_for_player.html('');
  29. _object_for_player.append(jplayer_player);
  30. _object_for_player.append(jplayer_content);
  31. JQueryJson(url_element_get_stream_data+'/'+ref_id, {}, function(response){
  32. if (response.status == 'success')
  33. {
  34. if (response.data)
  35. {
  36. for(var i = 0; i < response.data.length; i++)
  37. {
  38. var song = new GenericSong(response.data[i].name, response.data[i].url);
  39. _playlist[i] = song;
  40. }
  41. _player = new jPlayerPlaylist
  42. (
  43. {
  44. jPlayer: '#jplayer_player_element_'+ref_id,
  45. cssSelectorAncestor: '#jplayer_content_element_'+ref_id
  46. },
  47. _playlist,
  48. {
  49. playlistOptions:
  50. {
  51. autoPlay: true,
  52. enableRemoveControls: true
  53. },
  54. swfPath: "/jplayer/js",
  55. supplied: "mp3",
  56. wmode: "window"
  57. }
  58. );
  59. var _player_dom = $('#jplayer_player_element_'+ref_id);
  60. _player_dom.bind($.jPlayer.event.play, event_play_callback);
  61. _player_dom.bind($.jPlayer.event.ended, event_end);
  62. _player_dom.bind($.jPlayer.event.error, event_error);
  63. }
  64. else
  65. {
  66. _callback_event_finish_playlist();
  67. }
  68. }
  69. else
  70. {
  71. _callback_event_finish_playlist();
  72. }
  73. });
  74. }
  75. var event_play = function(event)
  76. {
  77. _current_index = _player.current;
  78. _callback_event_play(event);
  79. }
  80. var event_end = function(event)
  81. {
  82. _callback_event_end(event);
  83. if (_current_index+1 == _playlist.length)
  84. {
  85. event_finish_playlist(event);
  86. }
  87. }
  88. var event_error = function(event)
  89. {
  90. _callback_event_error(event);
  91. }
  92. var event_finish_playlist = function(event)
  93. {
  94. _callback_event_finish_playlist(event);
  95. }
  96. this.play = function(play_callback)
  97. {
  98. _player_dom.jPlayer("play");
  99. play_callback();
  100. }
  101. this.stop = function()
  102. {
  103. //_player_dom.jPlayer("stop");
  104. }
  105. this.pause = function()
  106. {
  107. _player_dom.jPlayer("pause");
  108. }
  109. this.destroy = function()
  110. {
  111. _object_for_player.html('');
  112. }
  113. this.enableFullScreen = function() {
  114. }
  115. this.disableFullScreen = function() {
  116. }
  117. }
  118. function GenericSong(title, mp3)
  119. {
  120. this.title = title;
  121. this.mp3 = mp3;
  122. }