gpt4 book ai didi

javascript - Angular 不会更改 json 中的音频源

转载 作者:行者123 更新时间:2023-12-02 14:38:01 26 4
gpt4 key购买 nike

我正在尝试使用音频标签将音频文件嵌入到 HTML 中。播放音频的src是从API获取的,我有5-6个不同的音频文件。

当我点击 playStart() 时,播放的音频文件是相同的,即使 src 显示不同的链接

<tbody>
<tr ng-repeat="val in values track by $index">
<td ng-bind="$index +1">1</td>
<td ng-bind="val._id">ED1500322</td>
<td>
<audio id="audioTag">
<source controls ng-src="{{val.file}}"></source>
</audio>

<button class="play-btn" ng-click="playStart()"><img src="app_static/images/play.png"></button>
<button class="play-btn" ng-click="playStop()">stop</button>
</td>
<td ng-bind="val.result"></td>

</tr>
</tbody>

JS文件

$scope.playStart = function() {
var audio = document.getElementById("audioTag");
audio.load();
audio.play();

};

$scope.playStop = function() {
var audio = document.getElementById("audioTag");
audio.pause();
audio.currentTime = 0;
};

即使 DOM 显示链接不同,我也只听到相同的音频剪辑

对于播放从 api 获得的音乐提供任何帮助,我们将不胜感激

最佳答案

使用类似的类:

HTML

<tbody>
<tr ng-repeat="val in values track by $index">
<td ng-bind="$index +1">1</td>
<td ng-bind="val._id">ED1500322</td>
<td>
<audio class="audioTag">
<source controls ng-src="{{val.file}}"></source>
</audio>

<button class="play-btn" ng-click="playStart($index)"><img src="app_static/images/play.png"></button>
<button class="play-btn" ng-click="playStop($index)">stop</button>
</td>
<td ng-bind="val.result"></td>

</tr>

JS

$scope.playStart = function(index_) {
var audio = document.getElementsByClassName("audioTag")[index_];
audio.load();
audio.play();

};

$scope.playStop = function() {
var audio = document.getElementsByClassName("audioTag")[index_];
audio.pause();
audio.currentTime = 0;
};

关于javascript - Angular 不会更改 json 中的音频源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37271357/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com