我可以从 Controller 提供我的 mp3 文件,但从我的控制器提供的文件不会在 ios AvPlayer 中播放(使用 url)。我确信我的客户端代码没问题,因为它可以播放其他服务器上的歌曲。您也可以通过我在末尾编写的链接检查我的服务器,并看到我的 Controller 正在提供该文件。
我应该向 AvPlayer 的响应添加任何特定 header 以支持我的网址吗?
现在我的 Laravel Controller 代码:
$response = new BinaryFileResponse($file);
BinaryFileResponse::trustXSendfileTypeHeader();
return $response;
这是一个示例链接,可以按照我想要的方式工作 http://s3.amazonaws.com/kargopolov/BlueCafe.mp3
这是我的,不起作用 http://projectm.e-rundev.ir/api/song/download/11.mp3
如有任何指示,我们将不胜感激
最佳答案
这是有效的代码
$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);
关于php - 从 Laravel 为 iOS AvPlayer 提供 mp3 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43558919/