4

I am using Lumen and I have an audio file in my uploads/videos/. I want to return the URL of the exact path (like app.com/videos/one.mp4).

I have achieved same thing in a very bad-practiced way by putting /{fileName} in routes, giving /one.mp4 and by removing the extension from String as soon as I receive the data (one.mp4). This is a bad way because I'm using a plugin that only accepts direct links.

(So for example, when I take link from any mp4 link (with extension), it works, but when I try it with my method, it doesn't

I found this example for Laravel, however Lumen apparently doesn't accept ->where:

Route::get('file/{filename}', 'FileController@getFile')->where('filename', '^[^/]+$');

and

 public function getFile($filename)
 {
  return response()->download(storage_path($filename), null, [], null);
 }

But when I try it in Lumen, I receive:

Call to undefined method Laravel\Lumen\Application::where()

What is the way of setting a route that receives filename with extension as parameters and returns the mp4 file in directory. So basically, I want to hit url myapi.com/videos/two.mp4 and play two.mp4 as soon as I hit to the link.

(Please note that I store the filename in database without extension, just as two for two.mp4.)

Example link format: https://v.cdn.vine.co/r/videos/12B2B2092B1284614590713798656_4be40e9deb2.4.1.3029273185552527049.mp4

Update:

This below chunk plays the audio in Chrome but not the app, may it be because of the app itself rather than Lumen? But it's playing successfully the above Vine link.

$app->get('/player/{filename}', 'PlayerController@show')

public function show ($filename)
{
    $this->playVid($filename, 'videos');
}

public function playVid($filename, $showType)
{
    if (file_exists("../uploads/" . $showType . "/" . $filename)) {
        $finfo = finfo_open(FILEINFO_MIME_TYPE);
        $type = finfo_file($finfo, "../uploads/" . $showType . "/" . $filename);

        header("Content-Type: " . $type);
        readfile("../uploads/" . $showType . "/" . $filename);
    }
}

If so, what is the difference between my file & Vine file? When I open both of the videos in browser, right+click and check source, both videos have type="video/mp4"


More information on Question: https://stackoverflow.com/questions/34369823/same-video-from-my-api-url-doesnt-work-where-works-from-online-url-from-proj

Update: I realised my problem was caused because I was using readFile, but I wanted to use streaming. If you believe that's the problem, refer here - https://stackoverflow.com/a/34435905/4705339

Community
  • 1
  • 1
senty
  • 12,385
  • 28
  • 130
  • 260
  • I think that your code is fine. Did you got some errors or what exactly when you've tried with your video ? Also, don't forget that browser can play a limited number of video formats, take a look on [my answer for this question](http://stackoverflow.com/a/27995270/2256820) ... – akmozo Dec 08 '15 at 14:19
  • I try it with an ios demo app - [Player](https://github.com/piemonte/Player). Interestingly, both my videos' and demo vine videos' format have `type="video/mp4"` and both plays on Browser (chrome pc). However, in the demo ios app, vine video works fine whereas my one just gets black screen. No errors or anything :/ What can be the problem? May it be related with codec (or something else)? Or am I doing something wrong by using this kind of route and controller method? – senty Dec 08 '15 at 20:19

0 Answers0