我正在使用Angular.js和一些Jquery来点击一些按钮播放声音。这是html代码:
[112] pry(main)> @entries = Entry.scheduled_between(start_date, end_date).pluck('detail_organization_id')
(0.6ms) SELECT "entries"."detail_organization_id" FROM "entries" INNER JOIN "daily_logs" ON "daily_logs"."id" = "entries"."daily_log_id" WHERE ("daily_logs"."calendar_date" BETWEEN $1 AND $2) [["calendar_date", "01/06/2017"], ["calendar_date", "01/06/2017"]]
=> [60, 60, 69]
这是我的功能代码:
<audio id="audio">
<source src="https://s3.amazonaws.com/freecodecamp/simonSound1.mp3"></source>
<source src="https://s3.amazonaws.com/freecodecamp/simonSound2.mp3"></source>
<source src="https://s3.amazonaws.com/freecodecamp/simonSound3.mp3"></source>
<source src="https://s3.amazonaws.com/freecodecamp/simonSound4.mp3"></source>
</audio>
<button class='t-l bt' ng-click='play_sound(0)'></button>
<button class='t-r bt' ng-click='play_sound(1)'></button>
<button class='b-l bt' ng-click='play_sound(2)'></button>
<button class='b-r bt' ng-click='play_sound(3)'></button>
当我将0作为参数传入并且在传递其他数字时失败时,该函数有效。这是我在谷歌控制台中得到的:
$scope.play_sound = function(order){
var audio = $('#audio')[order];
audio.play();
}
答案 0 :(得分:0)
你可以在下面试试。想法是获取单个源文件并根据订单播放该音频。
$scope.play_sound = function(order){
var audioSource = $('#audio source')[order];
var audio = new Audio(audioSource.attr("src");
audio.play();
}