如何在laravel中从数据库播放和下载音频

问题描述 投票:0回答:1

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

简单的解决方案是可以使用HTML <audio>标签。

  <audio controls>
  <source src="/mp3/{{$record->recording_filename}}" type="audio/mpeg"> 
  </audio>

它将为Play/PauseDownload提供选项>

供下载,请尝试此

  <a class="btn btn-success" href="/mp3/{{$record->recording_filename}}" download>Download</a>
© www.soinside.com 2019 - 2024. All rights reserved.