Serve mp3 file from laravel for iOS AvPlayer

后端 未结 1 1878
情深已故
情深已故 2021-01-07 04:12

I am able to serve my mp3 file from a controller, but the file served from my controller will not get played in ios AvPlayer (using url). I\'m sure that my client code is fi

相关标签:
1条回答
  • 2021-01-07 04:31

    here is the code that worked

        $file = storage_path() . '/upload/song/' . $filename;
        $mime_type = "audio/mpeg";
        $headers = array(
            'Accept-Ranges: 0-' . (filesize($file) -1) ,
    
            'Content-Length:'.filesize($file),
            'Content-Type:' . $mime_type,
            'Content-Disposition: inline; filename="'.$filename.'"'
    
        );
        $fileContents = File::get($file);
        return Response::make($fileContents, 200, $headers);
    
    0 讨论(0)
提交回复
热议问题