|
2
|
1 |
IriSP.Widgets.MusitagAnnotations = function(player, config) { |
|
|
2 |
IriSP.Widgets.Widget.call(this, player, config); |
|
|
3 |
}; |
|
|
4 |
|
|
|
5 |
IriSP.Widgets.MusitagAnnotations.prototype = new IriSP.Widgets.Widget(); |
|
|
6 |
|
|
30
|
7 |
IriSP.Widgets.MusitagAnnotations.prototype.template = |
|
|
8 |
'<div class="Musitag-Annotations-Main"></div><div id="Musitag-Annotations-Audioplayer"></div>'; |
|
|
9 |
|
|
|
10 |
IriSP.Widgets.MusitagAnnotations.prototype.annotation_template = |
|
56
|
11 |
'<div class="Musitag-Annotations-tag" begin-time="{{annotation.begin.milliseconds}}" title="{{annotation.color.name}}, {{annotation.emoticon.name}} {{l10n.at_timecode}} {{annotation.begin}}">' |
|
30
|
12 |
+ '<div class="Musitag-container-50">' |
|
|
13 |
+ '<div class="Musitag-shadow"></div>' |
|
56
|
14 |
+ '<div class="Musitag-color Musitag-{{annotation.color.tag}}"></div>' |
|
|
15 |
+ '<div class="Musitag-emoticon Musitag-{{annotation.emoticon.tag}}"></div>' |
|
59
|
16 |
+ '</div>{{#annotation.audio}}<div class="Musitag-Annotations-Balloon" audio-url="{{annotation.audio.href}}" title="{{l10n.play_voice}}"></div>{{/annotation.audio}}' |
|
30
|
17 |
+ '</div>'; |
|
|
18 |
|
|
56
|
19 |
IriSP.Widgets.MusitagAnnotations.prototype.messages = { |
|
|
20 |
fr: { |
|
59
|
21 |
at_timecode: "à", |
|
|
22 |
play_voice: "Lire l'annotation vocale" |
|
56
|
23 |
}, |
|
|
24 |
en: { |
|
59
|
25 |
at_timecode: "at", |
|
|
26 |
play_voice: "Play voice annotation" |
|
56
|
27 |
} |
|
|
28 |
} |
|
|
29 |
|
|
2
|
30 |
IriSP.Widgets.MusitagAnnotations.prototype.defaults = { |
|
40
|
31 |
annotation_type: false, |
|
2
|
32 |
columns: 15, |
|
|
33 |
max_by_column: 10, |
|
54
|
34 |
emoticons: [ |
|
|
35 |
{ tag: "happy", name: "content"}, |
|
|
36 |
{ tag: "unhappy", name: "mécontent"}, |
|
56
|
37 |
{ tag: "laughing", name: "rieur"}, |
|
54
|
38 |
{ tag: "surprised", name: "étonné"} |
|
|
39 |
], |
|
|
40 |
colors: [ |
|
|
41 |
{ tag: "red", name: "rouge"}, |
|
|
42 |
{ tag: "yellow", name: "jaune"}, |
|
|
43 |
{ tag: "green", name: "vert"}, |
|
|
44 |
{ tag: "blue", name: "bleu"} |
|
|
45 |
], |
|
30
|
46 |
rtmp_streamer: "rtmp://media.iri.centrepompidou.fr/ddc_micro_record/" |
|
2
|
47 |
}; |
|
|
48 |
|
|
|
49 |
IriSP.Widgets.MusitagAnnotations.prototype.draw = function() { |
|
30
|
50 |
this.renderTemplate(); |
|
38
|
51 |
this.bindPopcorn("IriSP.MusitagAnnotations.redraw","redraw"); |
|
30
|
52 |
this.$main = this.$.find(".Musitag-Annotations-Main"); |
|
|
53 |
var _this = this; |
|
|
54 |
this.jwplayer = jwplayer("Musitag-Annotations-Audioplayer"); |
|
|
55 |
this.jwplayer.setup({ |
|
|
56 |
flashplayer: IriSP.getLib("jwPlayerSWF"), |
|
|
57 |
width: 1, |
|
|
58 |
height: 1, |
|
|
59 |
provider: "rtmp", |
|
|
60 |
events: { |
|
|
61 |
onPause: function() { |
|
|
62 |
_this.setPlayState(false); |
|
|
63 |
}, |
|
|
64 |
onIdle: function() { |
|
|
65 |
_this.setPlayState(false); |
|
|
66 |
} |
|
|
67 |
} |
|
|
68 |
}); |
|
|
69 |
this.current_audio = false; |
|
60
|
70 |
this.annotation_playing = false; |
|
|
71 |
this.media_playing = !this.player.popcorn.media.paused; |
|
30
|
72 |
this.redraw(); |
|
|
73 |
} |
|
|
74 |
|
|
|
75 |
IriSP.Widgets.MusitagAnnotations.prototype.setPlayState = function(_playState) { |
|
60
|
76 |
this.annotation_playing = _playState; |
|
30
|
77 |
if (_playState) { |
|
|
78 |
this.$main.find(".Musitag-Annotations-Balloon").addClass("pause"); |
|
|
79 |
} else { |
|
|
80 |
this.$main.find(".Musitag-Annotations-Balloon").removeClass("pause"); |
|
60
|
81 |
if (this.media_playing) { |
|
|
82 |
this.player.popcorn.play(); |
|
|
83 |
} |
|
30
|
84 |
} |
|
|
85 |
} |
|
|
86 |
|
|
|
87 |
IriSP.Widgets.MusitagAnnotations.prototype.redraw = function() { |
|
|
88 |
|
|
2
|
89 |
var _html = '', |
|
|
90 |
_annotations = this.getWidgetAnnotations(), |
|
|
91 |
_duration = this.source.getDuration().milliseconds, |
|
|
92 |
_sliceDuration = _duration/this.columns, |
|
|
93 |
_this = this; |
|
|
94 |
_annotations.forEach(function(_annotation) { |
|
|
95 |
var _tags = _annotation.getTagTexts(); |
|
54
|
96 |
_annotation.emoticon = IriSP._(_this.emoticons).find(function(_emoticon) { |
|
|
97 |
return IriSP._(_tags).find(function(_tag) { |
|
|
98 |
return _tag == _emoticon.tag; |
|
|
99 |
}); |
|
|
100 |
}); |
|
|
101 |
_annotation.color = IriSP._(_this.colors).find(function(_color) { |
|
|
102 |
return IriSP._(_tags).find(function(_tag) { |
|
|
103 |
return _tag == _color.tag; |
|
|
104 |
}); |
|
2
|
105 |
}); |
|
|
106 |
}); |
|
|
107 |
for (var i = 0; i < this.columns; i++) { |
|
|
108 |
var _sliceStart = i * _sliceDuration, |
|
|
109 |
_sliceEnd = (i+1) * _sliceDuration, |
|
|
110 |
_column = _annotations.filter(function(_annotation) { |
|
|
111 |
return _annotation.begin >= _sliceStart |
|
|
112 |
&& _annotation.begin < _sliceEnd |
|
54
|
113 |
&& _annotation.emoticon |
|
|
114 |
&& _annotation.color |
|
2
|
115 |
}).sortBy(function(_annotation) { |
|
|
116 |
return _annotation.created; |
|
|
117 |
}); |
|
|
118 |
if (_column.length > this.max_by_column) { |
|
|
119 |
_column = _column.slice(_column.length - this.max_by_column, _column.length); |
|
|
120 |
} |
|
|
121 |
_html += '<div class="Musitag-Annotations-column">'; |
|
|
122 |
_html += _column.map(function(_annotation) { |
|
56
|
123 |
return Mustache.to_html(_this.annotation_template, { annotation: _annotation, l10n: _this.l10n }); |
|
2
|
124 |
}).join(''); |
|
|
125 |
_html += '</div>'; |
|
|
126 |
} |
|
30
|
127 |
this.$main.html(_html); |
|
|
128 |
this.$main.find('.Musitag-Annotations-tag .Musitag-container-50').click(function() { |
|
4
|
129 |
var _el = IriSP.jQuery(this).parent(); |
|
3
|
130 |
_this.player.popcorn.currentTime(_el.attr("begin-time") / 1000); |
|
|
131 |
}); |
|
30
|
132 |
this.$main.find('.Musitag-Annotations-tag').mouseover(function() { |
|
4
|
133 |
var _el = IriSP.jQuery(this); |
|
|
134 |
_this.$.find('.Musitag-Annotations-Balloon').hide(); |
|
|
135 |
_el.find('.Musitag-Annotations-Balloon').show(); |
|
|
136 |
}); |
|
30
|
137 |
this.$main.find('.Musitag-Annotations-Balloon').click(function() { |
|
|
138 |
var _el = IriSP.jQuery(this), |
|
|
139 |
_audiofile = _el.attr("audio-url").replace(_this.rtmp_streamer,""); |
|
60
|
140 |
if (_this.annotation_playing) { |
|
30
|
141 |
_this.jwplayer.pause(); |
|
|
142 |
_this.loadAudio(_audiofile); |
|
|
143 |
} else { |
|
|
144 |
_this.loadAudio(_audiofile); |
|
|
145 |
_this.jwplayer.play(); |
|
|
146 |
_this.setPlayState(true); |
|
60
|
147 |
_this.media_playing = !_this.player.popcorn.media.paused; |
|
|
148 |
if (_this.media_playing) { |
|
|
149 |
_this.player.popcorn.pause(); |
|
|
150 |
} |
|
30
|
151 |
} |
|
|
152 |
}); |
|
|
153 |
} |
|
|
154 |
|
|
|
155 |
IriSP.Widgets.MusitagAnnotations.prototype.loadAudio = function(_audiofile) { |
|
|
156 |
if (this.current_audio !== _audiofile) { |
|
|
157 |
this.jwplayer.load({ |
|
|
158 |
file: _audiofile, |
|
|
159 |
streamer: this.rtmp_streamer |
|
|
160 |
}); |
|
|
161 |
this.current_audio = _audiofile; |
|
|
162 |
} |
|
|
163 |
} |