<symbol id="chevron-bold" viewBox="0 0 2.5 3.5">
<polygon points="0.7,0 2.5,1.8 0.7,3.5 0,2.8 1.1,1.8 0,0.7"/>
</symbol>
+ <symbol id="play" viewBox="0 0 18 18">
+ <path d="M16,8.6c0.3,0.2,0.3,0.7,0,0.9l-6.7,3.8l-6.7,3.8c-0.3,0.2-0.8,0-0.8-0.4V9V1.5c0-0.4,0.4-0.6,0.8-0.4l6.7,3.8L16,8.6z"/>
+ </symbol>
</svg>
--- /dev/null
+function FluidbookAudioPlayer(fluidbook) {
+ this.fluidbook = fluidbook;
+ this.init();
+}
+
+FluidbookAudioPlayer.prototype = {
+ init: function () {
+ var $this = this;
+ $(document).on('click', "audio:not([controls])", function () {
+ console.log(this);
+ if (this.paused) {
+ this.play();
+ $(this).addClass('playing');
+ } else {
+ this.pause();
+ $(this).removeClass('playing');
+ }
+ return false;
+ });
+ requestAnimationFrame(function () {
+ $this.updatePlayers();
+ });
+
+ },
+
+
+ initAudios() {
+ var $this = this;
+ $('audio.redbull').each(function () {
+ $this.initRedbullPlayer(this);
+ });
+ },
+
+
+ updatePlayers: function () {
+ var $this = this;
+ $('audio.playing.redbull').each(function () {
+ $this.updateRedbullPlayer(this);
+ });
+ requestAnimationFrame(function () {
+ $this.updatePlayers();
+ });
+ },
+
+ /**
+ *
+ * @param player Audio
+ */
+ updateRedbullPlayer: function (player) {
+ var paper = $(player).data(paper);
+ var halfw = $(player).data('halfw');
+ var sw = 3;
+ paper.clear();
+ var p = Math.max(0, Math.min(1, player.currentTime / player.duration));
+ var arc = paper.path(this.arc([halfw, halfw], halfw - sw, 270, 270 + (p * 360)));
+ arc.attr('stroke', "#d7104e");
+ arc.attr('stroke-width', sw);
+ },
+
+
+ initRedbullPlayer: function (player) {
+ var vp = $(player).next('.visualPlayer');
+
+ vp.append('<div class="back"></div>');
+ vp.append('<div class="icon">' + getSpriteIcon('play') + '</div>');
+ vp.append('<div class="arc"></div>');
+
+ var vpw = Math.max($(vp).outerWidth(), $(vp).outerHeight());
+ $(player).data('halfw', vpw / 2);
+
+ var paper = Raphael(vp.find('.arc').get(0), vpw, vpw);
+ $(player).data(paper);
+ },
+
+
+ arc: function (center, radius, startAngle, endAngle) {
+ angle = startAngle;
+ coords = this.toCoords(center, radius, angle);
+ path = "M " + coords[0] + " " + coords[1];
+ while (angle <= endAngle) {
+ coords = this.toCoords(center, radius, angle);
+ path += " L " + coords[0] + " " + coords[1];
+ angle += 1;
+ }
+ return path;
+ },
+
+ toCoords: function (center, radius, angle) {
+ var radians = (angle / 180) * Math.PI;
+ var x = center[0] + Math.cos(radians) * radius;
+ var y = center[1] + Math.sin(radians) * radius;
+ return [x, y];
+ },
+
+ // draw an arc
+ // centered at (100, 100),
+ // radius 80, starting at degree 0,
+ // beginning at coordinate (80, 0)
+ // which is relative to the center
+ // of the circle,
+ // going clockwise, until 270 degree
+}
\ No newline at end of file