Skip to content
Snippets Groups Projects

Dev#14091 Audio Album Playing Mode

Merged Patrick Barroca requested to merge dev#14091-audio-album-playing-mode into WIP
Compare and
+ 145
18
Preferences
Compare changes
Files
<?php
/**
* Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved.
*
* AFI-OPAC 2.0 is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* AFI-OPAC 2.0 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with AFI-OPAC 2.0; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class ZendAfi_View_Helper_AlbumAudioJsPlayer extends Zend_View_Helper_HtmlElement {
use Trait_Translator;
public function __call($name, $args) {
if ('tag' == $name)
return call_user_func_array([$this->view, 'tag'], $args);
return parent::__call($name, $args);
}
public function albumAudioJsPlayer($album) {
$audiojs_path = URL_ADMIN_JS.'audiojs/audiojs/';
$options = ['swfLocation' => URL_ADMIN_JS.'audiojs/audiojs/audiojs.swf',
'imageLocation' => URL_ADMIN_JS.'audiojs/audiojs/player-graphics.gif'];
Class_ScriptLoader::getInstance()
->addStyleSheet(URL_ADMIN_JS.'audiojs/audiojs/style-light.css')
->addAdminScript('audiojs/audiojs/audio.min.js')
->addInlineScript('
$(function() {
var a = audiojs.createAll({
swfLocation: "' . $audiojs_path . 'audiojs.swf",
imageLocation: "' . $audiojs_path . 'player-graphics.gif",
trackEnded: function() {
var next = $("ol li.playing").next();
if (!next.length) next = $("ol li.audio_track").first();
next.click();
}
});
// Load in the first track
var audio = a[0];
first = $("ol li.audio_track a").attr("data-src");
$("ol li.audio_track").first().addClass("playing");
audio.load(first);
// Load in a track on click
$("ol li.audio_track").click(function(e) {
e.preventDefault();
$(this).addClass("playing").siblings().removeClass("playing");
audio.load($("a", this).attr("data-src"));
audio.play();
});
$(".audio_tracks_control .previous").click(function(e) {
e.preventDefault();
var prev = $("li.playing").prev();
if (!prev.length) prev = $("ol li.audio_track").last();
prev.click();
});
$(".audio_tracks_control .next").click(function(e) {
e.preventDefault();
var next = $("li.playing").next();
if (!next.length) next = $("ol li.audio_track").first();
next.click();
});
});');
return $this->renderAudioControl() . $this->renderTracksOf($album);
}
protected function renderAudioControl() {
return
$this->tag('audio', '', ['preload' => 'preload']) .
$this->tag('div',
$this->tag('a', '&lt;&lt; '. $this->_('Piste précédente'),
['href' => '#', 'class' => 'previous']) .
$this->tag('a', $this->_('Piste suivante') . ' &gt;&gt;',
['href' => '#', 'class' => 'next']),
['class' => 'audio_tracks_control']);
}
protected function renderTracksOf($album) {
$html = '';
foreach($album->getAudioTracks() as $track)
$html .= $this->renderTrack($track);
return $this->tag('ol', $html);
}
protected function renderTrack($track) {
return $this->tag(
'li',
$this->tag('a', $this->view->albumRessourceInfos($track),
['href' => '#',
'data-src' => $this->view->album_PlayRessourceUrl($track)]),
['class' => 'audio_track']);
}
}
?>
\ No newline at end of file