Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function prePersist(MediaInterface $media)
 {
     if (is_null($file = $media->getFile())) {
         return;
     }
     parent::prePersist($media);
     $size = getimagesize($file);
     $media->setMetadata(['width' => $size[0], 'height' => $size[1]]);
 }
 /**
  * Get the full url to the original file.
  *
  * @param MediaInterface $media
  *
  * @return string
  */
 public function getUrl(MediaInterface $media)
 {
     return $this->urlGenerator->generate($media->getReference());
 }
 /**
  * Save the thumbnail
  *
  * @param  MediaInterface $media The Youtube Object
  * @param  string         $url
  *
  * @return MediaInterface The newly created image
  */
 public function saveThumbnail(MediaInterface $media, $url)
 {
     $thumb = $this->mediaManager->createMedia();
     $thumb->setStatus(Media::STATUS_HASPARENT)->setName($media->getName() . '_thumb')->setProvider('image');
     $filename = '/tmp/' . basename($url);
     $filesystem = new Filesystem();
     $filesystem->dumpFile($filename, file_get_contents($url));
     $thumb->temp = $filename;
     $thumb->setFile(new UploadedFile($filename, basename($url)));
     $this->mediaManager->save($thumb);
     return $thumb;
 }
Exemple #4
0
 /**
  * Get the full url to the original video.
  *
  * @param MediaInterface $media
  *
  * @return string
  */
 public function getUrl(MediaInterface $media)
 {
     $metadata = $media->getMetaData();
     return sprintf('https://youtube.com/?watch=%s', $metadata['id']);
 }
Exemple #5
0
 /**
  * Get the full url to the original file.
  *
  * @param MediaInterface $media
  *
  * @return string
  */
 public function getUrl(MediaInterface $media)
 {
     return $this->getUrlByReference($media->getReference());
 }