Search code examples
phpamazon-web-servicesaudioamazon-s3audio-streaming

Stream audio from S3 with php and support Range


I am currently allowing users to listen to raw audio files by acting as a proxy to s3:

$result = $s3Client->getObject(array(
    'Bucket' => "Bucket",
    'Key' => "Key
));

Then just setting the appropriate headers and putting the data in the body.

This works although it has two drawbacks:

1) There is a high latency on large files because it takes time to download from s3

2) Chrome renders the audio in its own UI but when the user seeks using the scroll bar a request is sent with a "Range" header that is unhandled.

Does anyone have a better solution that handles these two issues? I've looked at the Amazon S3 Stream Wrapper, but i'm unclear on how to get this to stream audio back to the browser.


Solution

  • Use S3 to serve your media directly.

    If you wish to restrict access, you can pre-sign URLs with the S3 client. These URLs can be set up to only work for a few minutes.

    If for some reason you can't just link to S3 directly, you can in your current script just redirect to the S3 URL.