CodeIgniter Forums
Play Audio file in writable folder - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Play Audio file in writable folder (/showthread.php?tid=79886)



Play Audio file in writable folder - rafinhaa - 08-09-2021

Is it possible to play audio files that are inside the writable folder?

Code:
<audio controls="">
    <source src="C:\wamp64\www\cdr\writable\audios\2021\04\06\1617722381.169-221-20523678-12%3A19%3A41.wav">
</audio>

I have this code on the front end, but the audio doesn't play.

Thank you all!


RE: Play Audio file in writable folder - wuuyun - 08-09-2021

premise : the public is the webroot
two ways
1, add new folder example 'uploads' in public/ . then upload files in it (public/uploads)
2, make the (your writable/uploads full path) softlink to public/uploads . then upload filed in (writable/uploads full path)


RE: Play Audio file in writable folder - InsiteFX - 08-10-2021

Try this, not tested.
Code:
<audio controls="">
    <source src="<?= base_url(WRITEPATH.'audios\2021\04\06\1617722381.169-221-20523678-12%3A19%3A41.wav');?>">
</audio>

See if that will work for you.

UPDATE:

I found out that chrome and any web browsers using the chrome engine will give the error.

What I did to get it to work was to play the audio files from my live server then it worked.

Could be public_html or public depends on the server mine is public_html

Code:
<audio controls autoplay>
    <source src="https://www.your_server_name.com/assets/audio/bubble.mp3" type="audio/mpeg">
    Your browser does not support the audio element.
</audio>

Set audio folder permissions to 755
All have only read access owner has read/write/execute permissions.

Worked like a charm.


RE: Play Audio file in writable folder - rafinhaa - 08-10-2021

I tried as follows, but to no avail.

moved files from writable to public/assets/audios

PHP Code:
<audio controls>
      <source src="<?= base_url('assets/audios/'.$line["audiofile"]) ?>" type="audio/mpeg">
      Your browser does not support the audio element.
</
audio

base_url('assets/audios/'.$line["audiofile"]) print:
http://cdr.local/assets/audios/2021/08/10/1628604444.32-FX0-atendimento-11h07m29s.WAV

directly accessing the url in browser
[Image: Screenshot_1.png?1628606412]


RE: Play Audio file in writable folder - paliz - 08-10-2021

Upload your file to public /upload


You cannot read file from writable folder


RE: Play Audio file in writable folder - rafinhaa - 08-10-2021

(08-10-2021, 08:13 AM)paliz Wrote: Upload your file to public /upload


You cannot read file from writable folder

Yes! i moved files from folder writable to public/assets/audios

I found the problem was the file's codec
Code:
Input File    : 'public/assets/audios/2021/08/10/1628601745.4-FX0-atendimento-10:22:32.WAV'
Channels      : 1
Sample Rate    : 8000
Precision      : 16-bit
Duration      : 00:00:07.08 = 56640 samples ~ 531 CDDA sectors
File Size      : 11.6k
Bit Rate      : 13.1k
Sample Encoding: GSM

I did the test with another file and everything worked
Code:
Input File    : 'public/assets/audios/2021/04/06/1617722381.169-221-20523678-12:19:41.wav'
Channels      : 1
Sample Rate    : 8000
Precision      : 16-bit
Duration      : 00:00:25.38 = 203040 samples ~ 1903.5 CDDA sectors
File Size      : 406k
Bit Rate      : 128k
Sample Encoding: 16-bit Signed Integer PCM

Thanks to everyone who helped!