MP4 video file streamer for laravel

v0.2 2023-06-28 20:06 UTC

This package is auto-updated.

Last update: 2024-04-28 22:03:29 UTC


README

Tests

Beamer is a simple solution to streaming MP4 videos to any browser. Even Safari.

Installation

As usual, install Beamer using Composer:

composer require thepublicgood/beamer

You can publish the configuration file with:

php ./artisan vendor:publish --provider="TPG\Beamer\BeamerServiceProvider"

Where to store videos

By default Beamer will source videos from a videos directory inside storage/app. You can configure this in the configuration file by changing the disk and path settings.

Usage

Beamer is fairly simple. It only really does one thing. Once you have a video in the correct place, you’ll need to create a new route and a controller.

First the controller:

namespace App\Http\Controllers;

use TPG\Beamer\Facades\Beamer;

class BeamerController extends Controller
{
    public function __invoke(string $filename)
    {
        return Beamer::make($filename)->start();
    }
}

Then the route:

Route::get('/videos/{video}', BeamerController::class);

Open a browser and enter the URL for that route and include the filename of the video:

http://localhost:3000/videos/myvideo.mp4

Beamer doesn’t include the route or controller by default as you might want to customize this in your apps. For example, you might need to do some sort of authorization in the controller, or you might want to customize what the route looks like.