如何在 laravel 中播放和下载数据库中的音频
How to play and download audio from database in laravel
请帮我解决问题...这是我从数据库播放和下载音频的代码。我是编码新手..所以我不知道如何做 javascript 部分..音频在数据库中..所以我不知道如何获取 id
<table id="mytable" class="table table-bordred table-striped">
<thead>
<th id="wid2"> Recording Id </th>
<th id="wid1"> Unique Id</th>
<th id="wid1"> Phone Number</th>
<th id="wid1"> Date Time</th>
<th id="wid1">Call Type</th>
<th id="wid1"> Extension</th>
<th id="wid1">Recordings</th>
</thead>
<tbody>
<tr>
@foreach($records as $record)
<td id="wid2">{{$record->recording_id}}</td>
<td id="wid2">{{$record->uniqueid}}</td>
<td id="wid1">{{$record->phone_number}}</td>
<td id="wid1">{{$record->datetime}}</td>
<td id="wid1">{{$record->call_type}}</td>
<td id="wid1">{{$record->extension}}</td>
<td id="wid1"><a class="btn btn-primary" id="next" href="/mp3/{{$record->recording_filename}}"
onclick="return playAudio();">Play</a>
<a class="btn btn-success" id="" href="/mp3/{{$record->recording_filename}}"
>Donload</a>
</td>
</tr>
@endforeach
</tbody>
</table>
//script for this
<script type="text/javascript">
var x = document.getElementById('next');
//alert(x);
function playAudio() {
x.play();
}
</script>
简单的解决方案是您可以使用 HTML <audio>
标签。
<audio controls>
<source src="/mp3/{{$record->recording_filename}}" type="audio/mpeg">
</audio>
它将为 Play/Pause
和 Download
提供选项
要下载试试这个
<a class="btn btn-success" href="/mp3/{{$record->recording_filename}}" download>Download</a>
请帮我解决问题...这是我从数据库播放和下载音频的代码。我是编码新手..所以我不知道如何做 javascript 部分..音频在数据库中..所以我不知道如何获取 id
<table id="mytable" class="table table-bordred table-striped">
<thead>
<th id="wid2"> Recording Id </th>
<th id="wid1"> Unique Id</th>
<th id="wid1"> Phone Number</th>
<th id="wid1"> Date Time</th>
<th id="wid1">Call Type</th>
<th id="wid1"> Extension</th>
<th id="wid1">Recordings</th>
</thead>
<tbody>
<tr>
@foreach($records as $record)
<td id="wid2">{{$record->recording_id}}</td>
<td id="wid2">{{$record->uniqueid}}</td>
<td id="wid1">{{$record->phone_number}}</td>
<td id="wid1">{{$record->datetime}}</td>
<td id="wid1">{{$record->call_type}}</td>
<td id="wid1">{{$record->extension}}</td>
<td id="wid1"><a class="btn btn-primary" id="next" href="/mp3/{{$record->recording_filename}}"
onclick="return playAudio();">Play</a>
<a class="btn btn-success" id="" href="/mp3/{{$record->recording_filename}}"
>Donload</a>
</td>
</tr>
@endforeach
</tbody>
</table>
//script for this
<script type="text/javascript">
var x = document.getElementById('next');
//alert(x);
function playAudio() {
x.play();
}
</script>
简单的解决方案是您可以使用 HTML <audio>
标签。
<audio controls>
<source src="/mp3/{{$record->recording_filename}}" type="audio/mpeg">
</audio>
它将为 Play/Pause
和 Download
要下载试试这个
<a class="btn btn-success" href="/mp3/{{$record->recording_filename}}" download>Download</a>