Help us understand the problem. What is going on with this article?

How to enable seek for audio tag by Laravel5.5 Audioタグでシークを有効にする

More than 1 year has passed since last update.

Laravel5.5で、mp3ファイルへのリンクを直接貼るのではなく、アプリケーションからバイナリを
返却するようにしたい時、Accept-Ranges、Content-Rangeヘッダをレスポンスに追加するとaudioタグでシークできるようになる

You can enable to seek in audio tags by adding "Accept-Ranges" and "Content-Range" headers.

controller

class AudioController extends Controller
{
    public function loadAudio(Request $request)
    {
        //S3からオーディオファイルの取得
        $audioFile = Storage::disk('s3')->get('test_audio.mp3');

        $fullSize = strlen($audioFile);
        $startByte = 0;
        $endByte = $fullSize - 1;
        return response($audioFile)
            ->header('Content-Type', 'audio/mpeg')
            ->header('Content-Length', $fullSize)
            ->header('Accept-Ranges', 'bytes')
            ->header('Content-Range', 'bytes '.$startByte.'-'.$startByte.'/'.$endByte);
    }
}

view file

<audio controls>
    <source src="{{ route('audio.route', compact('key')) }}" type="audio/wav">
    Your browser does not support the audio element.
</audio>

参考URL:
https://forums.asp.net/t/2125393.aspx?Html+5+Audio+control+seek+is+not+working+

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした