从Laravel为iOS AvPlayer提供mp3文件 [英] Serve mp3 file from laravel for iOS AvPlayer

查看:91
本文介绍了从Laravel为iOS AvPlayer提供mp3文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够从控制器提供mp3文件,但是从控制器提供的文件无法在ios AvPlayer中播放(使用url).我确定我的客户端代码很好,因为它可以播放其他服务器上的歌曲.您也可以从我最后写的链接中检查我的服务器,并查看我的控制器正在提供文件.

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 fine, since it can play songs from other servers. also you may check my server from the link that I wrote at the end and see that my controller is serving the file.

我应该在响应中添加任何特定的标头以使AvPlayer支持我的网址吗?

should I add any specific header to the response for AvPlayer to support my url ?

我的laravel控制器代码:

my laravel controller code now:

    $response = new BinaryFileResponse($file);
    BinaryFileResponse::trustXSendfileTypeHeader();

    return $response;

这是一个示例链接,可按我的方式工作 http://s3.amazonaws.com /kargopolov/BlueCafe.mp3

here is a sample link that works how i want 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);

这篇关于从Laravel为iOS AvPlayer提供mp3文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆