-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmcplayer.js
More file actions
2218 lines (2006 loc) · 84.2 KB
/
mcplayer.js
File metadata and controls
2218 lines (2006 loc) · 84.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***********************************************************************
amcPlayer ... Axels Multi Channel Player
There are tons of html5 audio players around but I needed a special
feature: I wanted to play a song which is available in stereo and
5.1 surround with a single playlist item and switch between them.
--------------------------------------------------------------------------------
License: GPL 3.0 - http://www.gnu.org/licenses/gpl-3.0.html
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE
LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.
SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY
SERVICING, REPAIR OR CORRECTION.
--------------------------------------------------------------------------------
project home:
https://github.com/axelhahn/amcplayer/
https://www.axel-hahn.de/amcplayer
http://sourceforge.net/p/amcplayer/
docs:
https://www.axel-hahn.de/docs/amcplayer/index.htm
--------------------------------------------------------------------------------
*/
/**
* mcPlayer ... Multi Channel Player
*
* @author Axel Hahn
* @version 1.03
*
* @this mcPlayer
*
* @example
* // --- #1
* oMcPlayer=new mcPlayer();
* oMcPlayer.init(); // draw player gui
* oMcPlayer.minimize(true); // ... and hide the gui without animation
*
* // --- #2
* var oMcPlayer = new mcPlayer({
* settings:{
* autoopen: true,
* repeatlist: false
* }
* });
* oMcPlayer.init(); // draw player gui
* oMcPlayer.minimize(); // ... and hide the gui
*
* @constructor
* @return nothing
*/
var mcPlayer = function () {
// settings
this.cfg = {
about: {
version: '1.03',
label: 'AMC Player',
description: '<strong>A</strong>xels <strong>M</strong>ulti <strong>C</strong>hannel <strong>Player</strong>.<br>This is a webbased HTML5 audio player.<br>It\'s focus is the handling of media in stereo and surround for a title.',
labeldownload: 'Download:<br>',
download: 'http://sourceforge.net/projects/amcplayer/files/latest/download',
labellicense: 'License: ',
license: 'GPL 3.0',
labelurl: 'Project url:<br>',
url: 'https://github.com/axelhahn/amcplayer/',
labeldocurl: 'Documentation:<br>',
docurl: 'https://www.axel-hahn.de/docs/amcplayer/index.htm'
},
links: {
play: {
title: 'play'
}
},
aPlayer: {
buttons: {
//
// player controls
//
play: {
sticky: true,
title: 'Play'
},
pause: {
sticky: true,
title: 'Pause'
},
stop: {
sticky: true,
title: 'Stop'
},
backward: {
sticky: false,
title: 'Back'
},
forward: {
sticky: false,
title: 'Forward'
},
jumpprev: {
sticky: false,
title: 'Previous title'
},
jumpnext: {
sticky: false,
title: 'Next title'
},
audiochannels: {
title: 'switch between stereo/ surround',
noswitch: 'stereo/ surround switch was deactivated (mobile device or Opera Presto engine)'
},
//
// volume buttons
//
volmute: {
visible: true,
title: 'Mute'
},
volfull: {
visible: true,
title: 'Max. volume'
},
//
// other buttons
//
about: {
visible: true,
title: 'about ...',
box: 'mcpabout'
},
playlist: {
visible: true,
title: 'Toggle playlist',
box: 'mcpplaylist'
},
repeat: {
visible: true,
title: 'Repeat'
},
shuffle: {
visible: true,
title: 'Shuffle'
},
download: {
visible: true,
title: 'Toggle download list',
box: 'mcpdownloads'
},
maximize: {
label: 'Player',
sticky: false,
title: 'Show player'
},
minimize: {
label: '',
sticky: false,
title: 'Minimize'
},
statusbar: {
label: '',
title: 'Toggle statusbar with network activity and media status'
}
},
bars: {
volume: {
visible: true,
title: 'Set volume'
},
progress: {
visible: true,
title: 'Set position'
}
},
about: {
title: 'About ...'
},
playlist: {
title: 'Playlist'
},
download: {
title: 'Download audio files',
noentry: 'Select or play an audio first to show its downloads.',
hint: 'Use the right mousebutton or context menu to save the link target'
},
songinfo: {
album: 'Album',
year: 'Year',
bpmspeed: 'Speed',
bpm: 'bpm',
genre: 'Genre',
url: 'Web'
},
status: {
networkstate: {
label: 'Network activity',
0: ['Empty', '0 = NETWORK_EMPTY - audio/video has not yet been initialized'],
1: ['Idle', '1 = NETWORK_IDLE - audio/video is active and has selected a resource, but is not using the network'],
2: ['Loading', '2 = NETWORK_LOADING - browser is downloading data'],
3: ['No Source', '3 = NETWORK_NO_SOURCE - no audio/video source found']
},
readystate: {
label: 'Status',
0: ['Have nothing', '0 = HAVE_NOTHING - no information whether or not the audio/video is ready'],
1: ['Have Metadata', '1 = HAVE_METADATA - metadata for the audio/video is ready'],
2: ['OK, Current data', '2 = HAVE_CURRENT_DATA - data for the current playback position is available, but not enough data to play next frame/millisecond'],
3: ['OK, Future data', '3 = HAVE_FUTURE_DATA - data for the current and at least the next frame is available'],
4: ['OK, Enough data', '4 = HAVE_ENOUGH_DATA - enough data available to start playing']
}
}
},
settings: {
autoopen: false,
movable: true, // v0.26
repeatlist: true,
showsonginfos: true, // v0.29
showhud: true, // v0.30
showstatusbar: false, // v0.33
shuffle: false,
volume: 0.9
}
};
this.oAudio = false; // current audio object
this.sCurrentChannel = false; // current audio - one of false | "2.0"| "5.1"
this.iMaxVol = 1;
this.iCurrentTime = false; // aktuelle Abspielposition - bei Wechsel der Audioquelle
this.bIsFading = false; // Flag: erfolgt gerade ein X-Fading?
this.iVolInc = 0.02; // X-Fading: Schrittweite der Lautstaerke-Aenderung
this.iTimer = 20; // X-Fading: Intervall der Lautstaerke-Aenderung
this.iHudTimer = 5; // time to display hud message in s
this.iRemoveTimer = 2;
// get playlist of all audiotags of the current document
this.aPL = [];
this.iCurrentSong = -1;
this.aPlayorderList = [];
this.iPlaylistId = -1;
this._iMinDelta = 100;
this._sContainerId = false;
this.sScreensize = false;
this.name = false;
this.playlink = '[title]';
// **********************************************************************
/**
* Check: does the browser support 5.1 channels?<br>
* tablets and mobile devices: false<br>
* older Opera versions: false<br>
* all other: true<br>
*
* @return {boolean}
*/
this.canPlaySurround = function () {
var bReturn = true;
// older Opera makes a stereo downmixing of surround media
if (navigator.userAgent.indexOf("Presto/") >= 0) {
bReturn = false;
}
// tablets and other mobile, ... devices
// see https://stackoverflow.com/questions/11381673/detecting-a-mobile-browser#11381730
(function (a) {
if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4)))
bReturn = false;
})(navigator.userAgent || navigator.vendor || window.opera);
return bReturn;
};
/**
* scan AUDIO tags and its sources in a document to create an
* object with all current songs
* @private
* @return {Array}
*/
this._scanAudios = function () {
var oAudioList = document.getElementsByTagName("AUDIO");
var a = new Array();
var aSource = false;
var sChannels = false;
var aSong = false;
var o = false;
for (var i = 0; i < oAudioList.length; i++) {
oAudioList[i].style.display = "none";
aSong = {
title: oAudioList[i].dataset.title
? oAudioList[i].dataset.title
: oAudioList[i].title
? oAudioList[i].title
: ''
,
artist: oAudioList[i].dataset.artist ? oAudioList[i].dataset.artist : false,
album: oAudioList[i].dataset.album ? oAudioList[i].dataset.album : false,
year: oAudioList[i].dataset.year ? oAudioList[i].dataset.year : false,
image: oAudioList[i].dataset.image ? oAudioList[i].dataset.image : false,
genre: oAudioList[i].dataset.genre ? oAudioList[i].dataset.genre : false,
bpm: oAudioList[i].dataset.bpm ? oAudioList[i].dataset.bpm : false,
url: oAudioList[i].dataset.url ? oAudioList[i].dataset.url : false,
sources: {}
};
for (var j = 0; j < oAudioList[i].children.length; j++) {
o = oAudioList[i].children[j];
if (o.tagName === "SOURCE") {
sChannels = "any";
// if (o.dataset && o.dataset.ch)sChannels=o.dataset.ch;
if (o.title) {
sChannels = o.title;
}
aSource = {
src: o.src,
type: o.type
};
if (!aSong["sources"][sChannels])
dummy = aSong["sources"][sChannels] = new Array();
dummy = aSong["sources"][sChannels].push(aSource);
}
}
// add it to playlist
this.addAudio(aSong);
var newA = document.createElement("A");
newA.href = '#';
newA.title = this.cfg.links.play.title + ': ' + aSong.title;
// newA.innerHTML= this.playlink.replace('[title]', sTitle);
newA.innerHTML = this.playlink.replace('[title]', "");
newA.setAttribute('onclick', this.name + '.setSong(' + i + '); /* ' + this.name + '.maximize(); */ return false;');
newA.setAttribute('class', 'songbtn icon-play');
newA.setAttribute('id', 'mcpaudioPlay' + i);
oAudioList[i].parentNode.appendChild(newA);
}
return a;
};
/**
* add a song to the playlist
* @example
* {
* "title": "Ticker",
* "sources": {
* "2.0": [
* {
* "src": "https://www.axel-hahn.de/axel/download/ticker_2.0_.ogg",
* "type": "audio/ogg"
* },
* {
* "src": "https://www.axel-hahn.de/axel/download/ticker_2.0_.mp3",
* "type": "audio/mp3"
* }
* ],
* "5.1": [
* {
* "src": "https://www.axel-hahn.de/axel/download/ticker_5.1_.m4a",
* "type": "audio/mp4"
* },
* {
* "src": "https://www.axel-hahn.de/axel/download/ticker_5.1_.ogg",
* "type": "audio/ogg"
* }
* ]
* }
* }
* @param {array} aSong
* @returns {Boolean}
*/
this.addAudio = function (aSong) {
if (!aSong["sources"]) {
return false;
}
if (!aSong.title) {
aSong.title = 'audio ' + (this.aPL.length + 1);
}
this.aPL.push(aSong);
this._generatePlayorder();
};
/**
* get default html code of player controls
* @private
* @return {html_code}
*/
this._genPlayer = function () {
var s = '';
s += '<div id="mcpplayersonginfo"></div>';
// add buttons
var aTmp = new Array("play", "pause", "stop", "backward", "forward");
if (this.aPL.length > 1) {
aTmp.push("jumpprev", "jumpnext");
}
s += '<div id="mcpplayerbtndiv">';
for (var i = 0; i < aTmp.length; i++) {
s += '<a href="#" id="mcp' + aTmp[i] + '"'
+ ' onclick="' + this.name + '.playeraction(\'' + aTmp[i] + '\'); return false;' + '"'
+ ' title="' + this.cfg.aPlayer.buttons[aTmp[i]].title + '"'
+ '></a>';
}
s += '</div>'
+ '<div id="mcpprogressdiv"'
+ (this.cfg.aPlayer.bars["progress"].visible ? '' : 'style="display: none"')
+ '>'
// + '<canvas id="mcpprogresscanvas" title="' + this.cfg.aPlayer.bars["progress"].title + '"></canvas>'
+ '<div class="mcpslider">'
+ '<div class="mcpslider-default"></div>'
+ '<div id="mcpprogressbar" class="mcpslider-active"></div>'
+ '</div>'
+ '</div>'
+ '<span id="mcptime"><span id="mcptimeplayed">-:--</span>/ <span id="mcptimetotal">-:--</span></span>'
+ '<div id="mcpvolumesection">'
+ '<a href="#" id="mcpvolmute" onclick="' + this.name + '.setVolume(0); return false;" '
+ (this.cfg.aPlayer.buttons["volmute"].visible ? '' : 'style="display: none" ')
+ 'title="' + this.cfg.aPlayer.buttons["volmute"].title + '"></a>'
+ '<div id="mcpvolumediv" title="volume">'
// + '<canvas id="mcpvolumecanvas" '
// + (this.cfg.aPlayer.bars["volume"].visible ? '' : 'style="display: none" ')
// + 'title="' + this.cfg.aPlayer.bars["volume"].title + '"></canvas>'
+ '<div class="mcpslider">'
+ '<div class="mcpslider-default"></div>'
+ '<div id="mcpvolumebar" class="mcpslider-active"></div>'
+ '</div>'
+ '</div>'
+ '<a href="#" id="mcpvolfull" onclick="' + this.name + '.setVolume(1); return false;" '
+ (this.cfg.aPlayer.buttons["volfull"].visible ? '' : 'style="display: none" ')
+ 'title="' + this.cfg.aPlayer.buttons["volfull"].title + '"></a>'
+ '</div>'
+ '<div id="mcpchannels"></div>'
+ '<div id="mcpoptions">'
+ '<a href="#" onclick="' + this.name + '.toggleRepeat(); return false;" id="mcpoptrepeat" '
+ (this.isRepeatlist() ? 'class="active" ' : '')
+ 'title="' + this.cfg.aPlayer.buttons["repeat"].title + '"></a>'
+ '<a href="#" onclick="' + this.name + '.toggleShuffle(); return false;" id="mcpoptshuffle" '
+ (this.cfg.settings.shuffle ? 'class="active" ' : '')
+ 'title="' + this.cfg.aPlayer.buttons["shuffle"].title + '"></a>'
+ '<a href="#" onclick="' + this.name + '.toggleStatusbar(); return false;" id="mcpoptstatusbar" '
+ (this.isVisibleStatusbar() ? 'class="active" ' : '')
+ 'title="' + this.cfg.aPlayer.buttons["statusbar"].title + '"></a>'
;
var aBtn = ['download', 'playlist', 'about'];
for (var i = 0; i < aBtn.length; i++) {
idLink = 'mcpopt' + aBtn[i];
s += '<a href="#" onclick="' + this.name + '.toggleBoxAndButton(\'' + aBtn[i] + '\'); return false;" id="mcpopt' + aBtn[i] + '" '
+ (this.cfg.aPlayer.buttons[aBtn[i]].visible ? '' : 'style="display: none" ')
+ ' title="' + this.cfg.aPlayer.buttons[aBtn[i]].title + '"></a>'
;
}
s += '</div>'
+ '<div id="mcpstatusbar"'
+ (this.cfg.settings.showstatusbar ? ' class="active" ' : '')
+ '>'
+ '<div>'
+ this.cfg.aPlayer.status.networkstate.label + ': '
+ '<span id="mcpstatusnetwork"></span>'
+ '</div>'
+ '<div>'
+ this.cfg.aPlayer.status.readystate.label + ': '
+ '<span id="mcpstatusready"></span>'
+ '</div>'
+ '</div>'
;
return s;
};
/**
* generate html code for about box
* @private
* @return {html_code}
*/
this._genAboutbox = function () {
return '<div class="mcpbox">'
+ '<span class="ico-about"> ' + this.cfg.aPlayer.about.title + '</span>'
+ '<span class="mcpsystembutton"><a href="#" class="icon-down-open-1" onclick="' + this.name + '.toggleBoxAndButton(\'about\', \'minimize\'); return false;" title="' + this.cfg.aPlayer.buttons["minimize"].title + '">' + this.cfg.aPlayer.buttons["minimize"].label + '</a></span></div><div>'
+ '<p class="amclogo"></p>'
+ '<div class="title">' + this.cfg.about.label + ' v' + this.cfg.about.version + '</div>'
+ '<p>' + this.cfg.about.description + '</p>'
+ '<p>' + this.cfg.about.labellicense + '' + this.cfg.about.license + '</p>'
+ '<p>' + this.cfg.about.labelurl + '<a href="' + this.cfg.about.url + '" target="_blank">' + this.cfg.about.url + '</a></p>'
+ '<p>' + this.cfg.about.labeldownload + '<a href="' + this.cfg.about.download + '" target="_blank">' + this.cfg.about.download + '</a></p>'
+ '<p>' + this.cfg.about.labeldocurl + '<a href="' + this.cfg.about.docurl + '" target="_blank">' + this.cfg.about.docurl + '</a></p>'
+ '</div>';
};
/**
* generate html code for the playlist
* @private
* @return {html_code}
*/
this._genPlaylist = function () {
var sHtmlPL = ''
+ '<div class="mcpbox">'
+ '<span class="ico-playlist"> ' + this.cfg.aPlayer.playlist.title + '</span>'
+ '<span class="mcpsystembutton">'
+ '<a href="#" class="icon-down-open-1" onclick="' + this.name + '.toggleBoxAndButton(\'playlist\', \'minimize\'); return false;" '
+ 'title="' + this.cfg.aPlayer.buttons["minimize"].title + '">' + this.cfg.aPlayer.buttons["minimize"].label + '</a>'
+ '</span>'
+ '</div>'
;
if (this.aPL.length > 0) {
sHtmlPL += '<ul>';
for (var i = 0; i < this.aPL.length; i++) {
sHtmlPL += '<li'
+ (this.iCurrentSong === i ? ' class="active"' : '')
+ '><a href="#" onclick="' + this.name + '.setSong(' + i + '); return false;">'
+ (this.aPL[i]["title"] ? this.aPL[i]["title"] : "Audio #" + (i + 1))
+ '</a></li>';
}
sHtmlPL += '</ul>';
}
return sHtmlPL;
};
/**
* generate html code details of then current song
* @private
* @return {html_code}
*/
this._genSonginfos = function () {
if (!this.cfg.settings.showsonginfos) {
return '';
}
var sHtml = ''
+ (this.getSongArtist() ? '<div class="artist">' + this.getSongArtist() + '</div>' : '')
+ (this.getSongAlbum() ? '<div class="album">' + this.cfg.aPlayer.songinfo.album + ': ' + this.getSongAlbum() + '</div>' : '')
+ (this.getSongYear() ? '<div class="year">' + this.cfg.aPlayer.songinfo.year + ': ' + this.getSongYear() + '</div>' : '')
+ (this.getSongBpm() ? '<div class="bpm">' + this.cfg.aPlayer.songinfo.bpmspeed + ': ' + this.getSongBpm() + ' ' + this.cfg.aPlayer.songinfo.bpm + '</div>' : '')
+ (this.getSongGenre() ? '<div class="genre">' + this.cfg.aPlayer.songinfo.genre + ': ' + this.getSongGenre() + '</div>' : '')
+ (this.getSongUrl() ? '<div class="url">' + this.cfg.aPlayer.songinfo.url + ': <a href="' + this.getSongUrl() + '" target="_blank">' + this.getSongUrl() + '</a></div>' : '')
;
if (sHtml || this.getSongImage()) {
sHtml = '<div>'
+ (this.getSongImage() ? '<img src="' + this.getSongImage() + '">' : '')
+ (this.getSongTitle() ? '<div class="title">' + this.getSongTitle() + '</div>' : '')
+ sHtml
;
sHtml += '<div style="clear: both;"></div>';
sHtml += '</div>';
}
return sHtml;
};
/**
* scan AUDIO tags and its sources in a document to create an
* object with all current songs
* @private
* @return {html_code}
*/
this._genDownloads = function () {
var sHtml = '';
if (this.aPL.length > 0) {
sHtml += '<div class="mcpbox">'
+ '<span class="ico-download"> ' + this.cfg.aPlayer.download.title + '</span>'
+ '<span class="mcpsystembutton"><a href="#" class="icon-down-open-1" onclick="' + this.name + '.toggleBoxAndButton(\'download\', \'minimize\'); return false;" '
+ 'title="' + this.cfg.aPlayer.buttons["minimize"].title + '">' + this.cfg.aPlayer.buttons["minimize"].label + '</a>'
+ '</span>'
+ '</div>'
+ '<ul>'
;
if (this.iCurrentSong === -1) {
sHtml += '<li>' + this.cfg.aPlayer.download.noentry + '</li>';
} else {
sHtml += '<li>' + this.cfg.aPlayer.download.hint + '<br><br></li>';
for (var i = 0; i < this.aPL.length; i++) {
sSong = this.aPL[i]["title"];
if (!sSong) {
sSong = "Audio #" + (i + 1);
}
if (this.iCurrentSong === -1 || this.iCurrentSong == i) {
sHtml += '<li '
+ (this.iCurrentSong == i ? ' class="active"' : '')
+ '><strong>' + sSong + '</strong>'
+ '<ul>'
;
for (var sChannel in this.aPL[i]["sources"]) {
sHtml += '<li>' + sChannel + ': ';
for (j = 0; j < this.aPL[i]["sources"][sChannel].length; j++) {
sSrc = this.aPL[i]["sources"][sChannel][j]["src"];
sExt = this.aPL[i]["sources"][sChannel][j]["type"].replace('audio/', '');
// sExt='';
if (!sExt)
sExt = this.aPL[i]["sources"][sChannel][j]["src"].replace(/^.*\/|\.[^.]*$/g, '');
sHtml += (j > 0 ? ' | ' : '')
+ '<a href="' + this.aPL[i]["sources"][sChannel][j]["src"]
+ '" title="' + sSong + ' (' + sChannel + '; ' + sExt + ')' + "\n" + this.aPL[i]["sources"][sChannel][j]["src"] + '"'
+ '>' + sExt + '</a>';
}
sHtml += '</li>';
}
sHtml += '</ul></li>';
}
}
}
sHtml += '</ul>';
}
return sHtml;
};
/**
* read all audio tags in the page and create playlist
* @private
* @returns {undefined}
*/
this._generatePlaylist = function () {
// this.aPL = this._scanAudios();
this._scanAudios();
this._generatePlayorder();
};
/**
* helper function for generatePlayorder; shuffle javascript array
* @private
* @param {type} a
* @param {type} b
* @returns {Number}
*/
this._randomSort = function (a, b) {
return(parseInt(Math.random() * 10) % 2);
};
/**
* update playorder list with/ without shuffling
* @private
* @returns {undefined}
*/
this._generatePlayorder = function () {
this.aPlayorderList = [];
if (this.aPL.length) {
for (var i = 0; i < this.aPL.length; i++) {
this.aPlayorderList[i] = i;
}
if (this.isShuffled()) {
// on shuffling: current song will be the first element
if (this.iCurrentSong >= 0) {
this.aPlayorderList.splice(this.iCurrentSong, 1);
}
this.aPlayorderList.sort(this._randomSort);
if (this.iCurrentSong >= 0) {
this.aPlayorderList.unshift(this.iCurrentSong);
}
}
this._findPlaylistId();
}
};
/**
* get id in the playlist that matches the current song id
* @private
* @returns {Number|Boolean}
*/
this._findPlaylistId = function () {
this.iPlaylistId = false;
if (this.iCurrentSong >= 0) {
for (var i = 0; i < this.aPlayorderList.length; i++) {
if (this.aPlayorderList[i] === this.iCurrentSong) {
this.iPlaylistId = i;
}
}
}
return this.iPlaylistId;
};
this._addHtml = function (sHtml) {
oContainer=document.getElementById(this._sContainerId) ? document.getElementById(this._sContainerId) : document.getElementsByTagName("BODY")[0];
if(oContainer){
oContainer.innerHTML += sHtml;
}
}
// ----------------------------------------------------------------------
/**
* init html code of the player - by creating all missing elements
* @private
* @return nothing
*/
this._initHtml = function () {
var styleTop = ' style="top: ' + ((document.documentElement.clientHeight + 100) + 'px') + ';"';
this.oDivDownloads = document.getElementById("mcpdownloads");
if (!this.oDivDownloads) {
this._addHtml('<div id="mcpdownloads" class="draggable saveposition"' + styleTop + '></div>');
this.oDivDownloads = document.getElementById("mcpdownloads");
}
this.oDivDownloads.innerHTML = this._genDownloads();
this.oDivPlaylist = document.getElementById("mcpplaylist");
if (!this.oDivPlaylist) {
this._addHtml('<div id="mcpplaylist" class="draggable saveposition"' + styleTop + '></div>');
this.oDivPlaylist = document.getElementById("mcpplaylist");
}
this.oDivPlaylist.innerHTML = this._genPlaylist();
this.oDivPlayerwrapper = document.getElementById("mcpwrapper");
if (!this.oDivPlayerwrapper) {
this._addHtml('<div id="mcpwrapper"' + (this.cfg.settings.movable ? ' class="draggable saveposition"' : '') + '></div>');
this.oDivPlayerwrapper = document.getElementById("mcpwrapper");
}
this.oDivHeader = document.getElementById("mcpheader");
if (!this.oDivHeader) {
this.oDivPlayerwrapper.innerHTML += '<div id="mcpheader" class="mcpbox">' + '<span class="ico-playlist"> ' + this.cfg.about.label + ' v' + this.cfg.about.version + ' <span id="mcptitle"></span><span class="mcpsystembutton"><a href="#" class="icon-down-open-1" onclick="' + this.name + '.minimize(); return false" title="' + this.cfg.aPlayer.buttons["minimize"].title + '">' + this.cfg.aPlayer.buttons["minimize"].label + '</a></span></div>';
}
if (!this.oDivAudios) {
this.oDivPlayerwrapper.innerHTML += '<div id="mcpplayeraudios"></div>';
this.oDivAudios = document.getElementById("mcpplayeraudios");
}
this.oDivPlayer = document.getElementById("mcplayer");
if (!this.oDivPlayer) {
this.oDivPlayerwrapper.innerHTML += '<div id="mcplayer"></div>';
this.oDivPlayer = document.getElementById("mcplayer");
this.oDivPlayer.innerHTML = this._genPlayer();
}
this.oAPlayermaximize = document.getElementById("mcpmaximize");
if (!this.oAPlayermaximize) {
this._addHtml('<a href="#" id="mcpmaximize" class="mcpsystembutton hidebutton" onclick="' + this.name + '.maximize(); return false" title="' + this.cfg.aPlayer.buttons["maximize"].title + '"> ' + this.cfg.aPlayer.buttons["maximize"].label + '</a>');
this.oAPlayermaximize = document.getElementById("mcpmaximize");
}
this._addHtml('<div id="mcpabout" class="draggable saveposition"' + styleTop + '>' + this._genAboutbox() + '</div>');
this.oDivPlayerhud = document.getElementById("mcphud");
if (!this.oDivPlayerhud) {
this._addHtml('<div id="mcphud"></div>');
this.oDivPlayerhud = document.getElementById("mcphud");
}
this._playerheightSet();
};
// ----------------------------------------------------------------------
/**
* minimize player GUI and show a maximize icon
* @example
* <a href="#" onclick="oMcPlayer.minimize(); return false;">hide player</a>
* @param {boolean} bFast flag to override speed in css transistion
* @return nothing
*/
this.minimize = function (bFast) {
o = document.getElementById("mcpwrapper");
o.style['transition-duration'] = bFast ? '0s' : '';
o.style.top = (document.documentElement.clientHeight + this._iMinDelta) + 'px';
this.minimizeBox('about');
this.minimizeBox('download');
this.minimizeBox('playlist');
document.getElementById("mcpmaximize").className = '';
};
/**
* set if make the main player window is movable.
* This method is useful if you added drag and drop support (addi.min.js)
* for the windows but the main player is fixed on the bottom.
*
* @param {boolean} bMove flag true/ false
* @returns {undefined}
*/
this.makeMainwindowMovable = function (bMove) {
this.cfg.settings.movable = bMove;
o = document.getElementById("mcpwrapper");
if (this.cfg.settings.movable) {
o.className = 'draggable saveposition';
if (typeof addi !== 'undefined') {
addi.initDiv(o);
} else {
this.cfg.settings.movable = false;
}
}
if (!this.cfg.settings.movable) {
o.className = '';
if (typeof addi !== 'undefined') {
addi.resetDiv(o);
}
this.maximize();
o.setAttribute('style', '');
}
};
/**
* show/ maximize the player GUI
* @example
* <a href="#" onclick="oMcPlayer.maximize(); return false;">show the player</a>
*
* @return nothing
*/
this.maximize = function () {
o = document.getElementById("mcpwrapper");
o.setAttribute('style', '');
if (this.cfg.settings.movable && typeof addi !== 'undefined') {
addi.load(document.getElementById("mcpwrapper"));
}
document.getElementById("mcpmaximize").className = 'hidebutton';
};
/**
* show info in HUD div if
* - option showhud was set
* - option autoopen is false
* - player is invisible (minimized)
*
* @private
* @param {string} sMsg message to show in hud
* @return {boolean}
*/
this._showInfo = function (sMsg) {
if (!this.cfg.settings.showhud || this.cfg.settings.autoopen || this.isVisiblePlayer()) {
return false;
}
var o = document.getElementById("mcphud");
this.iRemoveTimer = this.iHudTimer * 1000;
o.className = 'active';
o.innerHTML = sMsg;
this._decHudTimer();
return true;
};
/**
* hide HUD div
* @private
* @return nothing
*/
this._hideInfo = function () {
var o = document.getElementById("mcphud");
o.className = '';
return true;
};
/**
* decrease time to display HUD; if it is zero then call hideInfo()
* @private
* @return nothing
*/
this._decHudTimer = function () {
this.iRemoveTimer = this.iRemoveTimer - 100;
// this.showInfo(this.iRemoveTimer);
if (this.iRemoveTimer > 0) {
window.setTimeout(this.name + "._decHudTimer()", 100);
} else {
this._hideInfo();
this.iRemoveTimer = false;
}
};
/**
* helper function for visible boxes
* @see toggleBoxAndButton()
* @private
* @param {string} sBaseId sBaseId of the div and the button; one of download|playlist|about
* @return {boolean}
*/
this._togglehelperGetDiv = function (sBaseId) {
return (this.cfg.aPlayer.buttons[sBaseId] && this.cfg.aPlayer.buttons[sBaseId].box)
? document.getElementById(this.cfg.aPlayer.buttons[sBaseId].box)
: (sBaseId === 'player')
? document.getElementById('mcpwrapper')
: false
;
};
/**
* toggle visibility of a box (download, playlist, about)
* @param {string} sBaseId sBaseId of the div and the button; one of download|playlist|about
* @param {string} sMode optional: force action; one of minimize|maximize; default behaviuor is toggle
* @param {boolean} bFast flag to override speed in css transistion
* @return {boolean}
*/
this.toggleBoxAndButton = function (sBaseId, sMode, bFast) {
var oDiv = this._togglehelperGetDiv(sBaseId);
var oBtn = document.getElementById('mcpopt' + sBaseId);
if (!sMode) {
sMode = (oBtn.className.indexOf('active') < 0 ? 'maximize' : 'minimize');
}
if (oDiv) {
// set a transition duration of "0s" sets it into the style and
// overrides delay from css; using bFast flag on startup removes
// the flickering on page load
oDiv.style['transition-duration'] = bFast ? '0s' : '';
}
if (sMode === 'minimize') {
if (oDiv) {
oDiv.style.top = (document.documentElement.clientHeight + this._iMinDelta) + 'px';
oDiv.style.opacity = 0.1;
}
if (oBtn) {
oBtn.className = '';
}
} else if (sMode === 'maximize') {
if (oDiv) {
// oDiv.className += ' visible';
oDiv.setAttribute('style', '');
oDiv.style.opacity = 1;
if (typeof addi !== 'undefined') {
addi.load(oDiv);
}
}
if (oBtn) {
oBtn.className = 'active';
}
}
return true;
};
/**
* return if a dialog box is visible
* @param {string} sBaseId sBaseId of the div and the button; one of download|playlist|about
* @returns {Boolean}
*/
this.isVisibleBox = function (sBaseId) {
// var oDiv=this._togglehelperGetDiv(sBaseId);
var sId = sBaseId === 'player' ? 'mcpmaximize' : 'mcpopt' + sBaseId
var oBtn = document.getElementById(sId);
return oBtn ? !!oBtn.className : false;
};
/**
* return if about dialog box is visible
* @returns {Boolean}
*/
this.isVisibleBoxAbout = function () {
return this.isVisibleBox('about');
};
/**
* return if download dialog box is visible
* @returns {Boolean}
*/
this.isVisibleBoxDownload = function () {
return this.isVisibleBox('download');
};
/**
* return if playlist dialog box is visible
* @returns {Boolean}
*/
this.isVisibleBoxPlaylist = function () {
return this.isVisibleBox('playlist');
};
/**
* return if player window is visible
* @since v0.30
* @returns {Boolean}
*/
this.isVisiblePlayer = function () {
return this.isVisibleBox('player');
};
/**
* return if player window is visible
* @since v0.33
* @returns {Boolean}
*/
this.isVisibleStatusbar = function () {
return this.cfg.settings.showstatusbar;
};
// ----------------------------------------------------------------------
/**
* toggle playing option repeat playlist
* @returns {undefined}
*/
this.toggleRepeat = function () {
if (this.isRepeatlist()) {
return this.disableRepeat();
} else {