Renders the media.

@param MediaInterface $media
@param array          $params
@return string
@throws \InvalidArgumentException
480383
public function renderMedia(MediaInterface $media, array $params = [])
    {
        switch ($media->getType()) {
            case MediaTypes::VIDEO :
                return $this->renderVideo($media, $params);
            case MediaTypes::FLASH :
                return $this->renderFlash($media, $params);
            case MediaTypes::AUDIO :
                return $this->renderAudio($media, $params);
            case MediaTypes::IMAGE :
                return $this->renderImage($media, $params);
            default:
                return $this->renderFile($media, $params);
        }
    }
456484
public function getImageResponse($path, array $params)
    {
        if (is_null($this->responseFactory)) {
            throw new InvalidArgumentException(
                'Unable to get image response, no response factory defined.'
            );
        }

        $path = $this->makeImage($path, $params);

        return $this->responseFactory->create($this->cache, $path);
    }
392763
public function getFormType(MediaInterface $media) {
        foreach ($this->strategies as $strategy) {
            if ($strategy->support($media)) {
                return $strategy->getFormType();
            }
        }

        return $this->defaultStrategy->getFormType();
    }
643349
public function getHtml(MediaInterface $media, $alias = null)
    {
        if ($media->getType() == $media::IMAGE) {
            $template = 'ApoutchikaMediaBundle:Render:image.html.twig';
        } elseif ($media->getType() == $media::VIDEO) {
            $template = 'ApoutchikaMediaBundle:Render:video.html.twig';
        } elseif ($media->getType() == $media::AUDIO) {
            $template = 'ApoutchikaMediaBundle:Render:audio.html.twig';
        } else {
            $template = 'ApoutchikaMediaBundle:Render:other.html.twig';
        }

        return $this->container->get('templating')->render($template, array(
            'media' => $media,
            'alias' => $alias,
            'url' => $this->getAbsoluteUrl($media, $alias),
        ));
    }
1123290
protected function getFormatChoices(MediaInterface $media = null)
    {
        $formatChoices = [];

        if (!$media instanceof MediaInterface) {
            return $formatChoices;
        }

        $formats = $this->getMediaPool()->getFormatNamesByContext($media->getContext());

        foreach ($formats as $code => $format) {
            $formatChoices[$code] = $code;
        }

        return $formatChoices;
    }
644171
public function render(array $params = []) {
        return trim(String::insert($this->getStatement(), $params + $this->getParams(), ['escape' => false])) . ';';
    }
526567
public function displayMediaForWysiwyg(MediaInterface $media, $format = '', $alt= '', $legend = '')
    {
        return $this->render(
            'OpenOrchestraMediaBundle:BBcode/WysiwygDisplay:image.html.twig',
            array(
                'media_url'    => $this->getMediaFormatUrl($media, $format),
                'media_alt'    => $alt,
                'media_id'     => $media->getId(),
                'media_format' => $format,
                'media_legend' => $legend,
            )
        );
    }
66377
public function prepareMedia(Media $media)
    {
        if (null === $media->getUuid()) {
            $uuid = uniqid();
            $media->setUuid($uuid);
        }
        $content = $media->getContent();
        if (empty($content)) {
            return;
        }
        if (!$content instanceof File) {
            if (!is_file($content)) {
                throw new \RuntimeException('Invalid file');
            }
            $file = new File($content);
            $media->setContent($file);
        }
        if ($content instanceof UploadedFile) {
            $pathInfo = pathinfo($content->getClientOriginalName());
            $media->setOriginalFilename($this->urlizer->urlize($pathInfo['filename']).'.'.$pathInfo['extension']);
            $name = $media->getName();
            if (empty($name)) {
                $media->setName($media->getOriginalFilename());
            }
        }
        $media->setFileSize(filesize($media->getContent()));
        $contentType = $this->mimeTypeGuesser->guess($media->getContent()->getPathname());
        $media->setContentType($contentType);
        $relativePath = sprintf('/%s.%s', $media->getUuid(), ExtensionGuesser::getInstance()->guess($media->getContentType()));
        $media->setUrl('/uploads/media'.$relativePath);
        $media->setLocation('local');
    }
1198871
protected function generateBinaryFromRequest(MediaInterface $media)
    {
        if (!$media->getContentType()) {
            throw new \RuntimeException(
                'You must provide the content type value for your media before setting the binary content'
            );
        }

        $request = $media->getBinaryContent();

        if (!$request instanceof Request) {
            throw new \RuntimeException('Expected Request in binary content');
        }

        $content = $request->getContent();

        // create unique id for media reference
        $guesser = ExtensionGuesser::getInstance();
        $extension = $guesser->guess($media->getContentType());

        if (!$extension) {
            throw new \RuntimeException(
                sprintf('Unable to guess extension for content type %s', $media->getContentType())
            );
        }

        $handle = tmpfile();
        fwrite($handle, $content);
        $file = new ApiMediaFile($handle);
        $file->setExtension($extension);
        $file->setMimetype($media->getContentType());

        $media->setBinaryContent($file);
    }
334814
public function getMediaFormatUrl(MediaInterface $media, $format)
    {
        $key = $media->getFilesystemName();

        if ($format != '' && MediaInterface::MEDIA_ORIGINAL != $format) {
            $key = $media->getAlternative($format);
        }

        return $this->getFileUrl($key);
    }
365082
public function renderMedia(MediaInterface $media, array $options = array())
    {
        $defaultOptions = $this->container->getParameter('thrace_media.jwplayer.options');
        $configs = array(
            'key' => $defaultOptions['key'],
            'html5player' => $defaultOptions['html5player'],
            'flashplayer' => $defaultOptions['flashplayer'],
            'type' => $media->getType(),
            'id' => uniqid('thrace_media', true),
            'file' => $this->container->get('router')->generate('thrace_media_render', array(
                'name' => $media->getMediaPath(),
                'hash' => $media->getHash()
            ), true)
        );
        
        $configs = array_replace_recursive($configs, $options);
        
        return $this->container->get('templating')
            ->render('ThraceMediaBundle:Media:media.html.twig',
                array('media' => $media, 'configs' => $configs)
            )
        ;
    }
1300909
protected function getMetadata(MediaInterface $media, $url)
    {
        try {
            $response = $this->browser->get($url);
        } catch (\RuntimeException $e) {
            throw new \RuntimeException('Unable to retrieve the video information for :'.$url, null, $e);
        }

        $metadata = json_decode($response->getContent(), true);

        if (!$metadata) {
            throw new \RuntimeException('Unable to decode the video information for :'.$url);
        }

        return $metadata;
    }
875366
public function generateThumbnail(MediaInterface $media)
    {
        $thumbnailName = $this->generateAlternative(
            $media->getFilesystemName(),
            self::THUMBNAIL_PREFIX,
            $this->thumbnailFormat
        );

        $media->setThumbnail($thumbnailName);
    }
13271
public function deleteAlternatives(MediaInterface $media)
    {
        foreach ($this->strategies as $strategy) {
            if ($strategy->support($media)) {
                $strategy->deleteAlternatives($media);

                return;
            }
        }

        $this->defaultStrategy->deleteAlternatives($media);
    }
600142
public function setMedia($media)
    {
        if (is_string($media)) {
            $this->media = $media;
        } else {
            $msg = "Media must be a string, '" . gettype($media) . "' given.";
            throw new InvalidArgumentException($msg);
        }
    }
970191
public function renderAction(ComponentInterface $component, ContentInterface $content)
    {
        if (!$mediaData = $component->getData('medias')) {
            // @todo log
            return new Response('');
        }

        return $this->get('synapse')
            ->createDecorator($component)
            ->decorate(array(
                'content' => $content,
                'medias' => $this->container->get('synapse.image.loader')
                    ->retrieveAll(array('id' => $component->getData('medias'))),
            ))
        ;
    }
926112
public function generateAlternatives(MediaInterface $media)
    {
        if ($media->getFilesystemName() != '') {
            $filePath = $this->tmpDir . DIRECTORY_SEPARATOR . $media->getFilesystemName();
            $this->fileSystem->remove(array($filePath));
        }
    }