benIT /
e-media
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace AppBundle\Controller; |
||||
| 4 | |||||
| 5 | use AppBundle\Entity\Video; |
||||
| 6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
||||
| 7 | use Symfony\Component\Filesystem\Filesystem; |
||||
| 8 | use Symfony\Component\HttpFoundation\BinaryFileResponse; |
||||
| 9 | use Symfony\Component\HttpFoundation\Request; |
||||
| 10 | use Symfony\Component\HttpFoundation\ResponseHeaderBag; |
||||
| 11 | |||||
| 12 | class StreamController extends Controller |
||||
| 13 | { |
||||
| 14 | use ControllerUtilsTrait; |
||||
| 15 | |||||
| 16 | /** |
||||
| 17 | * secure the HLS m3u8 and segment download |
||||
| 18 | * @param Request $request |
||||
| 19 | * @param Video $video |
||||
| 20 | * @param $file |
||||
| 21 | * @param $frameSize |
||||
| 22 | * @return BinaryFileResponse |
||||
| 23 | */ |
||||
| 24 | public function downloadHlsFileAction(Request $request, Video $video, $file, $frameSize) |
||||
|
0 ignored issues
–
show
|
|||||
| 25 | { |
||||
| 26 | $videoPath = $this->get('vich_uploader.storage')->resolvePath($video, 'videoFile'); |
||||
| 27 | $filePath = $frameSize ? pathinfo($videoPath)['dirname'] . '/' . $frameSize . '/' . $file : pathinfo($videoPath)['dirname'] . '/' . $file; |
||||
| 28 | $response = new BinaryFileResponse($filePath); |
||||
| 29 | $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE, basename($filePath)); |
||||
| 30 | return $response; |
||||
| 31 | } |
||||
| 32 | |||||
| 33 | |||||
| 34 | /** |
||||
| 35 | * Http Live Streaming |
||||
| 36 | * @see https://en.wikipedia.org/wiki/HTTP_Live_Streaming |
||||
| 37 | * @param Request $request |
||||
| 38 | * @param Video $video |
||||
| 39 | * @param $frameSize |
||||
| 40 | * @return \Symfony\Component\HttpFoundation\Response |
||||
| 41 | */ |
||||
| 42 | public function streamAction(Request $request, Video $video, $frameSize) |
||||
|
0 ignored issues
–
show
The parameter
$request is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 43 | { |
||||
| 44 | $videoPath = $this->get('vich_uploader.storage')->resolvePath($video, 'videoFile'); |
||||
| 45 | $fs = new Filesystem(); |
||||
| 46 | $playlistFile = getenv('HLS_PLAYLIST_NAME'); |
||||
| 47 | $playlistFileLocation = join('/', [pathinfo($videoPath)['dirname'], $frameSize, $playlistFile]); |
||||
| 48 | $errorFileLocation = join('/', [pathinfo($videoPath)['dirname'], $frameSize, 'error']); |
||||
| 49 | $lockFileLocation = join('/', [pathinfo($videoPath)['dirname'], $frameSize, 'lock']); |
||||
| 50 | $error = false; |
||||
| 51 | |||||
| 52 | if ($fs->exists($errorFileLocation)) { |
||||
| 53 | $error = $this->get('translator')->trans('encoding.error', [], 'stream'); |
||||
| 54 | $this->flashMessage(ControllerUtilsTrait::$flashDanger, $error); |
||||
| 55 | } elseif ($fs->exists($lockFileLocation)) { |
||||
| 56 | $error = $this->get('translator')->trans('encoding.pending', [], 'stream'); |
||||
| 57 | $this->flashMessage(ControllerUtilsTrait::$flashInfo, $error); |
||||
| 58 | } elseif (!$fs->exists($playlistFileLocation)) { |
||||
| 59 | $error = $this->get('translator')->trans('encoding.no-playlist', [], 'stream'); |
||||
| 60 | $this->flashMessage(ControllerUtilsTrait::$flashDanger, $error); |
||||
| 61 | } |
||||
| 62 | |||||
| 63 | |||||
| 64 | return $this->render('stream/stream.html.twig', array( |
||||
| 65 | 'error' => $error, |
||||
| 66 | 'video' => $video, |
||||
| 67 | 'frameSize' => $frameSize |
||||
| 68 | )); |
||||
| 69 | } |
||||
| 70 | } |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.