controllers/DownloadController.php
private function getConvertedAudioResponse(Request $request, Response $response)
    {
        $from = $request->getQueryParam('from');
        $to = $request->getQueryParam('to');

        $response = $response->withHeader(
            'Content-Disposition',
            'attachment; filename="'.
            $this->video->getFileNameWithExtension('mp3').'"'
        );
        $response = $response->withHeader('Content-Type', 'audio/mpeg');

        if ($request->isGet() || $request->isPost()) {
            try {
                $process = $this->video->getAudioStream($from, $to);
            } catch (Exception $e) {
                // Fallback to default format.
                $this->video = $this->video->withFormat($this->defaultFormat);
                $process = $this->video->getAudioStream($from, $to);
            }
            $response = $response->withBody(new Stream($process));
        }

        return $response;
    }
private function getConvertedAudioResponse(Request $request, Response $response)
    {
        $from = $request->getQueryParam('from');
        $to = $request->getQueryParam('to');

        $response = $response->withHeader(
            'Content-Disposition',
            'attachment; filename="'.
            $this->video->getFileNameWithExtension('mp3').'"'
        );
        $response = $response->withHeader('Content-Type', 'audio/mpeg');

        if ($request->isGet() || $request->isPost()) {
            try {
                $process = $this->video->getAudioStream($from, $to);
            } catch (Exception $e) {
                // Fallback to default format.
                $this->video = $this->video->withFormat($this->defaultFormat);
                $process = $this->video->getAudioStream($from, $to);
            }
            $response = $response->withBody(new Stream($process));
        }

        return $response;
    }
private function getConvertedAudioResponse ( Request $ request , Response $ response ) { $ from = $ request -> getQueryParam ( 'from' ) ; $ to = $ request -> getQueryParam ( 'to' ) ; $ response = $ response -> withHeader ( 'Content-Disposition' , 'attachment; filename="' . $ this -> video -> getFileNameWithExtension ( 'mp3' ) . '"' ) ; $ response = $ response -> withHeader ( 'Content-Type' , 'audio/mpeg' ) ; if ( $ request -> isGet ( ) || $ request -> isPost ( ) ) { try { $ process = $ this -> video -> getAudioStream ( $ from , $ to ) ; } catch ( Exception $ e ) { // Fallback to default format. $ this -> video = $ this -> video -> withFormat ( $ this -> defaultFormat ) ; $ process = $ this -> video -> getAudioStream ( $ from , $ to ) ; } $ response = $ response -> withBody ( new Stream ( $ process ) ) ; } return $ response ; }
Return a converted MP3 file.

@param Request  $request  PSR-7 request
@param Response $response PSR-7 response

@return Response HTTP response
Return a converted MP3 file .