ProjekktorAudioPlayer.php in AudioField 8
File
src/Plugin/AudioPlayer/ProjekktorAudioPlayer.php
View source
<?php
namespace Drupal\audiofield\Plugin\AudioPlayer;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\audiofield\AudioFieldPluginBase;
use Drupal\Component\Serialization\Json;
class ProjekktorAudioPlayer extends AudioFieldPluginBase {
public function renderPlayer(FieldItemListInterface $items, $langcode, array $settings) {
if (!$this
->checkInstalled()) {
$this
->showInstallError();
return $this
->renderDefaultPlayer($items, $settings);
}
$player_settings = [
'volume' => $settings['audio_player_initial_volume'] / 10,
'swfpath' => $this
->getPluginLibraryPath() . '/swf/Jarisplayer/jarisplayer.swf',
'files' => [],
'autoplay' => $settings['audio_player_autoplay'],
];
$template_files = $this
->getItemRenderList($items);
foreach ($template_files as $renderInfo) {
$player_settings['files'][] = $renderInfo->id;
}
return [
'audioplayer' => [
'#theme' => 'audioplayer',
'#plugin_id' => 'projekktor',
'#settings' => $settings,
'#files' => $template_files,
],
'downloads' => $this
->createDownloadList($items, $settings),
'#attached' => [
'library' => [
'audiofield/audiofield.' . $this
->getPluginLibraryName(),
],
'drupalSettings' => [
'audiofieldprojekktor' => [
$this
->getUniqueRenderId() => $player_settings,
],
],
],
];
}
public function getPluginLibraryVersion() {
$library_path = $this->fileSystem
->realpath(DRUPAL_ROOT . $this
->getPluginLibraryPath() . '/package.json');
$library_data = Json::decode(file_get_contents($library_path));
return $library_data['version'];
}
}