Search code examples
phpvlcplaylistm3u

PHP(laravel) to create a m3u playlist URL which is playable directly in VLC


I'm having an m3u playlist which downloads fine and works when open in VLC after the download. However I want that someone could just paste the URL to VLC and it would work directly without the need to download the file first. I'm using laravel for this but I don't need to. Here is the download code:

$headers = ["Content-Type: audio/x-mpegurl"];

// Trigger the download
return response()->download('/lists/edited.m3u', urlencode($username) . '.m3u', $headers);   

Solution

  • I figured it out...

    I had 2 mistakes with my initial code.

    First, it was laravels login auth class that wasn't allowing VLC to "see" the playlist. Since I'm performing my own authentication, I excluded the route from auth and it worked fine.

    Secondly, the header array was malformed. Here is the correct code:

    $headers = [
        'Content-Type' => 'audio/x-mpegurl',
     ];
    // Trigger the download
    

    return response()->download('/lists/edited.m3u', urlencode($username) . '.m3u',$headers);