1
|
|
|
/** |
2
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
3
|
|
|
* |
4
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
5
|
|
|
* |
6
|
|
|
* @license GNU General Public License version 3 or later. |
7
|
|
|
* For the full copyright and license information, please read the |
8
|
|
|
* LICENSE.txt file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @param {Object} settings |
13
|
|
|
* @constructor |
14
|
|
|
*/ |
15
|
|
|
var dlfAudioPlayer = function (settings) { |
16
|
|
|
|
17
|
|
|
var parentElId = settings.parentElId !== undefined ? settings.parentElId : 'tx-dlf-audio', |
18
|
|
|
swfPath = settings.swfPath !== undefined ? settings.swfPath : undefined, |
19
|
|
|
solutions = swfPath !== undefined ? 'html, flash' : 'html', |
20
|
|
|
audioOptions = settings.audio !== undefined ? settings.audio : undefined; |
21
|
|
|
|
22
|
|
|
if (audioOptions === undefined) |
23
|
|
|
throw new Error('Missing audio configurations.'); |
|
|
|
|
24
|
|
|
|
25
|
|
|
var format = dlfAudioPlayer.JPLAYER_MIMETYPE_FORMAT_MAPPING[audioOptions.mimeType] !== undefined |
26
|
|
|
? dlfAudioPlayer.JPLAYER_MIMETYPE_FORMAT_MAPPING[audioOptions.mimeType] |
27
|
|
|
: 'mp3'; |
28
|
|
|
audioOptions[format] = audioOptions.url; |
29
|
|
|
|
30
|
|
|
// |
31
|
|
|
// Load params |
32
|
|
|
// |
33
|
|
|
var jPlayerOptions = { |
34
|
|
|
ready: function() { |
35
|
|
|
$(this).jPlayer('setMedia', audioOptions) |
36
|
|
|
}, |
37
|
|
|
solution: solutions, |
38
|
|
|
supplied: format, |
39
|
|
|
cssSelectorAncestor: '#jp_container_1', |
40
|
|
|
useStateClassSkin: true, |
41
|
|
|
autoBlur: false, |
42
|
|
|
smoothPlayBar: true, |
43
|
|
|
keyEnabled: true, |
44
|
|
|
remainingDuration: false, |
45
|
|
|
toggleDuration: true |
46
|
|
|
}; |
47
|
|
|
|
48
|
|
|
if (swfPath !== undefined) { |
49
|
|
|
jPlayerOptions['swfPath'] = swfPath; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
// |
53
|
|
|
// Initialize the audio player |
54
|
|
|
// |
55
|
|
|
|
56
|
|
|
// player dom |
57
|
|
|
$('#' + parentElId).after('<div id="jp_container_1" class="jp-audio" role="application" aria-label="media player">' + |
58
|
|
|
'<div class="jp-type-single"><div class="jp-gui jp-interface"><div class="jp-volume-controls">' + |
59
|
|
|
'<button class="jp-mute" role="button" tabindex="0">mute</button><button class="jp-volume-max" role="button" tabindex="0">max volume</button>' + |
60
|
|
|
'<div class="jp-volume-bar"><div class="jp-volume-bar-value"></div></div></div><div class="jp-controls-holder">' + |
61
|
|
|
'<div class="jp-controls"><button class="jp-play" role="button" tabindex="0">play</button><button class="jp-stop" role="button" tabindex="0">stop</button>' + |
62
|
|
|
'</div><div class="jp-progress"><div class="jp-seek-bar"><div class="jp-play-bar"></div></div></div><div class="jp-current-time" role="timer" aria-label="time"> </div><span class="jp-duration-divider">/</span>' + |
63
|
|
|
'<div class="jp-duration" role="timer" aria-label="duration"> </div><div class="jp-toggles"><button class="jp-repeat" role="button" tabindex="0">repeat</button>' + |
64
|
|
|
'</div></div></div><div class="jp-details"><div class="jp-title" aria-label="title"> </div></div><div class="jp-no-solution">' + |
65
|
|
|
'<span>Update Required</span>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>.' + |
66
|
|
|
'</div></div></div>'); |
67
|
|
|
|
68
|
|
|
// jplayer init |
69
|
|
|
$('#' + parentElId).jPlayer(jPlayerOptions); |
70
|
|
|
}; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @type {{MP3: string}} |
74
|
|
|
*/ |
75
|
|
|
dlfAudioPlayer.JPLAYER_MIMETYPE_FORMAT_MAPPING = { |
76
|
|
|
'audio/mpeg': 'mp3', |
77
|
|
|
'audio/mp4': 'm4a', |
78
|
|
|
'audio/wav': 'wav' |
79
|
|
|
}; |
80
|
|
|
|
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.
Consider:
If you or someone else later decides to put another statement in, only the first statement will be executed.
In this case the statement
b = 42
will always be executed, while the logging statement will be executed conditionally.ensures that the proper code will be executed conditionally no matter how many statements are added or removed.