1var g_audioPlayer = null; 2var g_audio_playlist = []; 3var g_onPlaying = false; 4 5function openAudioPlayer(loc){ 6 7 var audio_array = new Array(); 8 for(var i=0;i<g_file_array.length;i++){ 9 var file_ext = getFileExt(g_file_array[i].href); 10 if(file_ext=="mp3") 11 audio_array.push(g_file_array[i]); 12 } 13 14 var audio_array_count = audio_array.length; 15 16 if(audio_array_count==0){ 17 alert(m.getString("msg_no_image_list")); 18 return; 19 } 20 21 var audio_list = ""; 22 var default_index = 0; 23 for(var i=0;i<audio_array.length;i++){ 24 var the_loc = audio_array[i].href; 25 26 if( loc == the_loc ) 27 default_index = i; 28 29 audio_list += the_loc; 30 if(i!=audio_array.length-1) audio_list += ","; 31 } 32 33 get_mp3_url(audio_list, true, function(audio_playlist){ 34 g_audioPlayer.showHideAudioPlayerWindow(true, function(){ 35 g_audioPlayer.addPlaylist(audio_playlist, default_index); 36 }); 37 }); 38} 39 40function openAudioPlayerByPlayList(playlist){ 41 if(playlist==null) return; 42 if(playlist.length<=0) return; 43 44 g_audioPlayer.addPlaylist(playlist, 0); 45 g_audioPlayer.showHideAudioPlayerWindow(true); 46} 47 48function getAudioPlayerLayout(){ 49 var layout_html = ""; 50 layout_html += "<div id='audioPlayerWindow' class='unselectable'>"; 51 layout_html += '<div id="audio-player-box">'; 52 layout_html += '<script type="text/javascript" src="/smb/js/jplayer/jquery.jplayer.min.js"></script>'; 53 layout_html += '<link rel="stylesheet" href="/smb/css/jplayer.blue.monday.css" type="text/css">'; 54 layout_html += '<div id="jquery_jplayer_1" class="jp-jplayer"></div>'; 55 layout_html += '<div id="jp_container_1" class="jp-audio">'; 56 layout_html += '<div class="jp-type-playlist">'; 57 layout_html += '<div id="jp_title_1" class="jp-title">'; 58 layout_html += '<ul>'; 59 layout_html += '<li>Loading...</li>'; 60 layout_html += '</ul>'; 61 layout_html += '</div>'; 62 layout_html += '<div id="jp_interface_1" class="jp-gui jp-interface">' 63 layout_html += '<ul class="jp-controls">'; 64 layout_html += '<li><a href="javascript:;" class="jp-previous" tabindex="1">previous</a></li>'; 65 layout_html += '<li><a href="javascript:;" class="jp-play" tabindex="1" style="display: block; ">play</a></li>'; 66 layout_html += '<li><a href="javascript:;" class="jp-pause" tabindex="1" style="display: block; ">pause</a></li>'; 67 layout_html += '<li><a href="javascript:;" class="jp-next" tabindex="1">next</a></li>'; 68 layout_html += '<li><a href="javascript:;" class="jp-stop" tabindex="1">stop</a></li>'; 69 layout_html += '<li><a href="javascript:;" class="jp-mute" tabindex="1" title="mute">mute</a></li>'; 70 layout_html += '<li><a href="javascript:;" class="jp-volume-max" tabindex="1" title="max volume">max volume</a></li>'; 71 layout_html += '</ul>'; 72 layout_html += '<div class="jp-progress">'; 73 layout_html += '<div class="jp-seek-bar" style="width: 100%; ">'; 74 layout_html += '<div class="jp-play-bar" style="width: 46.700506341691536%; "></div>'; 75 layout_html += '</div>' 76 layout_html += '</div>'; 77 layout_html += '<div class="jp-volume-bar">' 78 layout_html += '<div class="jp-volume-bar-value" style="width: 31.979694962501526%; "></div>'; 79 layout_html += '</div>'; 80 layout_html += '<div class="jp-duration-bar">'; 81 layout_html += '<div class="jp-duration">00:00</div>' 82 layout_html += '<div class="jp-split">/</div>'; 83 layout_html += '<div class="jp-current-time">00:00</div>'; 84 layout_html += '</div>'; 85 layout_html += '</div>'; 86 layout_html += '<div id="jp_playlist_1" class="jp-playlist">'; 87 layout_html += '<ul></ul>'; 88 layout_html += '</div>'; 89 layout_html += '</div>'; 90 layout_html += '</div>'; 91 layout_html += '<div class="jp-no-solution" style="display: none; ">'; 92 layout_html += '<span>Update Required</span>'; 93 layout_html += 'To play the media you will need to either update your browser to a recent version or update your <a href="http://get.adobe.com/flashplayer/" target="_blank">Flash plugin</a>.'; 94 layout_html += '</div>'; 95 layout_html += '<a id="audio-player-box-playlist" class="sicon" href="#" rel="playlist">Playlist</a>'; 96 layout_html += '<a id="audio-player-box-hide" class="sicon" href="#" rel="close">Hide</a>'; 97 layout_html += '<a id="audio-player-box-close" class="sicon" href="#" rel="close">Close</a>'; 98 layout_html += '</div>'; 99 layout_html += "</div>"; 100 layout_html += "<div id='audioPlayerStatusWindow' class='bicon' style='display:none'>"; 101 layout_html += "<div id='close-button'></div>"; 102 layout_html += "<div id='status-bar'>"; 103 layout_html += "<span id='status'></span>"; 104 layout_html += "</div>"; 105 layout_html += "</div>"; 106 107 return layout_html; 108} 109 110function get_mp3_url(audio_list, generate_sharelink, complete_handler){ 111 if(audio_list=="") 112 return; 113 114 var tmp_audio_playlist = g_audio_playlist; 115 var this_audio_list = audio_list.split(","); 116 var current_query_index = 0; 117 var on_query = false; 118 g_audio_playlist = []; 119 120 for(var i=0; i<tmp_audio_playlist.length; i++){ 121 for(var j=0; j<this_audio_list.length; j++){ 122 if(tmp_audio_playlist[i]["source"]==this_audio_list[j]){ 123 g_audio_playlist.push(tmp_audio_playlist[i]); 124 this_audio_list.splice(j, 1); 125 j=-1; 126 } 127 } 128 } 129 130 if(generate_sharelink){ 131 132 var media_hostName = window.location.host; 133 //if(media_hostName.indexOf(":")!=-1) 134 // media_hostName = media_hostName.substring(0, media_hostName.indexOf(":")); 135 //media_hostName = "http://" + media_hostName + ":" + g_storage.get("http_port") + "/"; 136 137 media_hostName = window.location.protocol + "//" + media_hostName + "/"; 138 139 var timer = setInterval(function(){ 140 141 if(on_query==false){ 142 143 if(current_query_index<0||current_query_index>this_audio_list.length-1){ 144 clearInterval(timer); 145 complete_handler(g_audio_playlist); 146 return; 147 } 148 149 var this_audio = this_audio_list[current_query_index]; 150 var this_file_name = this_audio.substring( this_audio.lastIndexOf("/")+1, this_audio.length ); 151 var this_url = this_audio.substring(0, this_audio.lastIndexOf('/')); 152 153 on_query = true; 154 g_webdav_client.GSL(this_url, this_url, this_file_name, 0, 0, function(error, content, statusstring){ 155 if(error==200){ 156 var data = parseXml(statusstring); 157 var share_link = $(data).find('sharelink').text(); 158 share_link = media_hostName + share_link; 159 160 on_query = false; 161 162 var obj = []; 163 obj['source'] = this_audio; 164 obj['name'] = mydecodeURI(this_file_name); 165 obj['mp3'] = share_link; 166 g_audio_playlist.push(obj); 167 168 current_query_index++; 169 } 170 }); 171 } 172 }, 100); 173 } 174 else{ 175 for(var i=0; i < this_audio_list.length;i++){ 176 var this_audio = this_audio_list[i]; 177 var this_file_name = this_audio.substring( this_audio.lastIndexOf("/")+1, this_audio.length ); 178 var this_url = this_audio.substring(0, this_audio.lastIndexOf('/')); 179 180 var obj = []; 181 obj['source'] = this_audio; 182 obj['name'] = mydecodeURI(this_file_name); 183 obj['mp3'] = this_audio; 184 g_audio_playlist.push(obj); 185 } 186 187 complete_handler(g_audio_playlist); 188 } 189 190 //tmp_audio_playlist = null; 191 //this_audio_list = null; 192} 193 194function initAudioPlayer(){ 195 196 var AudioPlayer = function(instance, options) { 197 var self = this; 198 this.clsoeAudioPlayerWindowTimer = 0; 199 this.statusMarqueeTimer = 0; 200 this.instance = instance; // String: To associate specific HTML with this playlist 201 this.playlist = null; // Array of Objects: The playlist 202 this.options = options; // Object: The jPlayer constructor options for this playlist 203 this.playTitle = ""; 204 this.current = 0; 205 this.showAudioList = false; 206 207 this.cssId = { 208 "jPlayer": "jquery_jplayer_", 209 "interface": "jp_interface_", 210 "playlist": "jp_playlist_", 211 "playtitle": "jp_title_" 212 }; 213 214 this.cssSelector = {}; 215 216 $.each(this.cssId, function(entity, id) { 217 self.cssSelector[entity] = "#" + id + self.instance; 218 }); 219 220 if(!this.options.cssSelectorAncestor) { 221 this['options']['cssSelectorAncestor'] = this['cssSelector']['interface']; 222 } 223 224 $(this.cssSelector.jPlayer).jPlayer(this.options); 225 226 var s = this['cssSelector']['interface'] + " .jp-previous"; 227 $(s).click(function() { 228 self.playlistPrev(); 229 $(this).blur(); 230 return false; 231 }); 232 233 s = this['cssSelector']['interface'] + " .jp-next"; 234 $(s).click(function() { 235 self.playlistNext(); 236 $(this).blur(); 237 return false; 238 }); 239 240 $("#audioPlayerWindow").mousemove(function(){ 241 self.startStopRunAudioPlayerWindowTimer(false); 242 }); 243 244 $("#audioPlayerWindow").mouseleave(function(){ 245 self.startStopRunAudioPlayerWindowTimer(true); 246 }); 247 248 $("#audio-player-box-hide").click(function(){ 249 self.showHideAudioPlayerWindow(false); 250 return false; 251 }); 252 253 $("#audio-player-box-close").click(function(){ 254 255 if(g_onPlaying && !confirm(m.getString('msg_close_audio_window_warning'))){ 256 return false; 257 } 258 259 self.closeAudioPlayWindow(); 260 261 return false; 262 }); 263 264 $("#audio-player-box-playlist").click(function(){ 265 self.showHideAudioList(!self.showAudioList); 266 }); 267 268 $("#audioPlayerStatusWindow").click(function(){ 269 self.showHideAudioPlayerWindow(true); 270 }); 271 272 $("#audioPlayerStatusWindow #close-button").click(function(){ 273 if(g_onPlaying && !confirm(m.getString('msg_close_audio_window_warning'))){ 274 return false; 275 } 276 277 self.closeAudioPlayWindow(); 278 279 return false; 280 }); 281 }; 282 283 AudioPlayer.prototype = { 284 getPlayTitle: function(){ 285 return this.playTitle; 286 }, 287 startStopRunAudioPlayerStatus: function(start){ 288 if(start){ 289 $('#audioPlayerStatusWindow').fadeIn('slow', function() { 290 this.statusMarqueeTimer = setInterval(function(){ 291 292 var len = String($("#audioPlayerStatusWindow #status").text()).width($("#audioPlayerStatusWindow #status").css("font")); 293 294 $('#audioPlayerStatusWindow #status').animate({ 295 left: -len 296 }, 5000, function() { 297 // Animation complete. 298 $('#audioPlayerStatusWindow #status').css("left", 80); 299 }); 300 }, 500); 301 }); 302 } 303 else{ 304 clearInterval(this.statusMarqueeTimer); 305 $("#audioPlayerStatusWindow").css("display", "none"); 306 } 307 }, 308 startStopRunAudioPlayerWindowTimer: function(start){ 309 var self = this; 310 if(start){ 311 //- Close Audio Player Window After 3 sec. 312 self.clsoeAudioPlayerWindowTimer = setTimeout( function(){ 313 self.showHideAudioPlayerWindow(false); 314 }, 10000 ); 315 } 316 else{ 317 clearInterval(self.clsoeAudioPlayerWindowTimer); 318 } 319 }, 320 showHideAudioPlayerWindow: function(bshow, completeHandler){ 321 var self = this; 322 if(bshow){ 323 //- Show Audio Player Window 324 self.startStopRunAudioPlayerWindowTimer(false); 325 326 self.startStopRunAudioPlayerStatus(false); 327 328 self.showHideAudioList(false); 329 330 if($('#audioPlayerWindow').css("display")=="none"){ 331 $('#audioPlayerWindow').fadeIn(500, function() { 332 self.startStopRunAudioPlayerWindowTimer(true); 333 334 if(completeHandler) 335 completeHandler(); 336 }); 337 } 338 else{ 339 self.startStopRunAudioPlayerWindowTimer(true); 340 341 if(completeHandler) 342 completeHandler(); 343 } 344 } 345 else{ 346 //- Hide Audio Player Window 347 if($('#audioPlayerWindow').css("display")=="block"){ 348 $('#audioPlayerWindow').fadeOut(500, function() { 349 //- Show Audio Player Status Window. 350 self.startStopRunAudioPlayerStatus(true); 351 self.showHideAudioList(false); 352 353 if(completeHandler) 354 completeHandler(); 355 }); 356 } 357 else{ 358 //- Show Audio Player Status Window. 359 self.startStopRunAudioPlayerStatus(true); 360 self.showHideAudioList(false); 361 362 if(completeHandler) 363 completeHandler(); 364 } 365 } 366 }, 367 showHideAudioInterface: function(bshow){ 368 if(bshow){ 369 $("#jp_interface_1").css("display","block"); 370 } 371 else{ 372 $("#jp_interface_1").css("display","none"); 373 } 374 }, 375 showHideAudioList: function(bshow){ 376 if(bshow){ 377 $(".jp-playlist").css("display", "block"); 378 } 379 else{ 380 $(".jp-playlist").css("display", "none"); 381 } 382 383 this.showAudioList = bshow; 384 }, 385 setPlaylist: function(playlist) { 386 this.playlist = playlist; 387 388 this.displayPlaylist(); 389 this.current = 0;//g_current_index; 390 this.playlistInit(true); // Parameter is a boolean for autoplay. 391 392 $("#playlist").css("visibility","visible"); 393 this.showHideAudioInterface(true); 394 this.showHideAudioList(false); 395 }, 396 addPlaylist: function(playlist, default_play_index) { 397 this.playlist = playlist; 398 399 this.displayPlaylist(); 400 this.current = default_play_index; 401 this.playlistInit(true); // Parameter is a boolean for autoplay. 402 403 $("#playlist").css("visibility","visible"); 404 this.showHideAudioInterface(true); 405 this.showHideAudioList(false); 406 }, 407 displayPlaylist: function() { 408 if(this.playlist==null||this.playlist==undefined) 409 return; 410 411 var self = this; 412 $(this.cssSelector.playlist + " ul").empty(); 413 414 for (i=0; i < this.playlist.length; i++) { 415 var filename = this.playlist[i].name; 416 var listItem = (i === this.playlist.length-1) ? "<li class='jp-playlist-last'>" : "<li>"; 417 listItem += "<a href='#' id='" + this.cssId.playlist + this.instance + "_item_" + i +"' tabindex='1'>"+ filename +"</a>"; 418 419 // Associate playlist items with their media 420 $(this.cssSelector.playlist + " ul").append(listItem); 421 422 $(this.cssSelector.playlist + "_item_" + i).data("index", i).click(function() { 423 var index = $(this).data("index"); 424 if(self.current !== index) { 425 self.playlistChange(index); 426 } 427 else { 428 $(self.cssSelector.jPlayer).jPlayer("play"); 429 } 430 $(this).blur(); 431 return false; 432 }); 433 } 434 }, 435 playlistInit: function(autoplay) { 436 if(autoplay) { 437 this.playlistChange(this.current); 438 } else { 439 this.playlistConfig(this.current); 440 } 441 }, 442 playlistConfig: function(index) { 443 $(this.cssSelector.playlist + "_item_" + this.current).removeClass("jp-playlist-current").parent().removeClass("jp-playlist-current"); 444 $(this.cssSelector.playlist + "_item_" + index).addClass("jp-playlist-current").parent().addClass("jp-playlist-current"); 445 this.current = parseInt(index); 446 447 var filename = this.playlist[this.current]['name']; 448 var full_filename = filename; 449 this.playTitle = filename; 450 //alert("play "+this.playlist[this.current].mp3); 451 452 $(this.cssSelector.playtitle + " li").attr("title",full_filename); 453 $(this.cssSelector.playtitle + " li").text(filename); 454 $(this.cssSelector.jPlayer).jPlayer("setMedia", this.playlist[this.current]); 455 }, 456 playlistChange: function(index) { 457 this.playlistConfig(index); 458 $(this.cssSelector.jPlayer).jPlayer("play"); 459 }, 460 playlistNext: function() { 461 var index = (this.current + 1 < this.playlist.length) ? this.current + 1 : 0; 462 this.playlistChange(index); 463 }, 464 playlistPrev: function() { 465 var index = (this.current - 1 >= 0) ? this.current - 1 : this.playlist.length - 1; 466 this.playlistChange(index); 467 }, 468 closeAudioPlayWindow:function() { 469 $(this.cssSelector.jPlayer).jPlayer("stop"); 470 471 this.startStopRunAudioPlayerStatus(false); 472 this.startStopRunAudioPlayerWindowTimer(false); 473 474 $('#audioPlayerStatusWindow').hide(); 475 $('#audioPlayerWindow').hide(); 476 } 477 }; 478 //////////////////////////////////////////////////////////////////////////////////////////////// 479 480 var jplayer_solution = "html,flash"; 481 var jplayer_supplied = "mp3"; 482 var browserVer = navigator.userAgent; 483 484 if( browserVer.indexOf("Chrome") != -1 || 485 browserVer.indexOf("Firefox") != -1 || 486 ( browserVer.indexOf("Safari") != -1 && ( isMacOS() || isWinOS() ) ) ){ 487 jplayer_solution = "html,flash"; 488 jplayer_supplied = "mp3"; 489 } 490 else if( isIE() || 491 browserVer.indexOf("Opera") != -1 ){ 492 jplayer_solution = "flash"; 493 jplayer_supplied = "mp3"; 494 } 495 496 g_audioPlayer = new AudioPlayer("1", { 497 ready: function() { 498 499 }, 500 ended: function() { 501 g_audioPlayer.playlistNext(); 502 g_storage.set('stopLogoutTimer', "0"); 503 }, 504 play: function() { 505 $(this).jPlayer("pauseOthers"); 506 g_storage.set('stopLogoutTimer', "1"); 507 }, 508 playing: function() { 509 $("#audioPlayerStatusWindow #status").text("playing: " + g_audioPlayer.getPlayTitle()); 510 g_onPlaying = true; 511 g_storage.set('stopLogoutTimer', "1"); 512 }, 513 pause: function() { 514 $("#audioPlayerStatusWindow #status").text("pause: " + g_audioPlayer.getPlayTitle()); 515 g_onPlaying = false; 516 g_storage.set('stopLogoutTimer', "0"); 517 }, 518 stop: function(){ 519 g_onPlaying = false; 520 g_storage.set('stopLogoutTimer', "0"); 521 }, 522 swfPath: "/smb/js/jplayer/", 523 supplied: jplayer_supplied, 524 solution: jplayer_solution, 525 wmode: "window", 526 errorAlerts: false, 527 warningAlerts: false, 528 error: function(event){ 529 var type = event.jPlayer.error.type; 530 if(type=="e_no_solution"){ 531 $(".jp-no-solution").html(m.getString("title_install_flash")); 532 $(".jp-no-solution").css("display", "block"); 533 } 534 else if(type=="e_url"){ 535 if(g_audio_playlist.length>1) 536 g_audioPlayer.playlistNext(); 537 } 538 } 539 }); 540 //////////////////////////////////////////////////////////////////////////////////////////////// 541 /* 542 $("#audio_player_panel").draggable({ 543 snap: 'true', 544 cursor: 'move', 545 opacity: 0.35, 546 containment: "#main_region" 547 }); 548 */ 549} 550