SoundManagerAudioPlayer.php in AudioField 8
File
src/Plugin/AudioPlayer/SoundManagerAudioPlayer.php
View source
<?php
namespace Drupal\audiofield\Plugin\AudioPlayer;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\audiofield\AudioFieldPluginBase;
use Drupal\Component\Serialization\Json;
class SoundManagerAudioPlayer extends AudioFieldPluginBase {
public function renderPlayer(FieldItemListInterface $items, $langcode, array $settings) {
if (!$this
->checkInstalled()) {
$this
->showInstallError();
return $this
->renderDefaultPlayer($items, $settings);
}
$template_settings = $settings;
$template_settings['count'] = count($items);
$player_settings = [
'volume' => $settings['audio_player_initial_volume'] * 10,
'swfpath' => $this
->getPluginLibraryPath() . '/swf/',
];
return [
'audioplayer' => [
'#theme' => 'audioplayer',
'#plugin_id' => 'soundmanager',
'#plugin_theme' => $settings['audio_player_soundmanager_theme'],
'#settings' => $template_settings,
'#files' => $this
->getItemRenderList($items),
],
'downloads' => $this
->createDownloadList($items, $settings),
'#attached' => [
'library' => [
'audiofield/audiofield.' . $this
->getPluginLibraryName(),
'audiofield/audiofield.' . $this
->getPluginLibraryName() . '.' . $settings['audio_player_soundmanager_theme'],
],
'drupalSettings' => [
'audiofieldsoundmanager' => [
$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'];
}
}