请帮助我解决问题...这是我的代码,可以从数据库播放和下载音频。我是编码方面的新手。所以我没有任何知识去做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>