31 lines
825 B
Plaintext
Executable File
31 lines
825 B
Plaintext
Executable File
<%= render_view %>
|
|
<script>
|
|
let audio;
|
|
$(".voice-player").on("click", function(){
|
|
let status = $(this).attr('status');
|
|
if (audio) {
|
|
audio.pause();
|
|
audio.currentTime = 0;
|
|
}
|
|
|
|
if (status == 'playing') {
|
|
$(this).attr('status', '');
|
|
$(this).find('i').removeClass('fa-pause');
|
|
$(this).find('i').addClass('fa-play');
|
|
} else {
|
|
let mp3_url = $(this).attr('data-content');
|
|
let _this = $(this);
|
|
audio = new Audio(mp3_url);
|
|
audio.play();
|
|
audio.onended = function() {
|
|
_this.attr('status', '');
|
|
_this.find('i').removeClass('fa-pause');
|
|
_this.find('i').addClass('fa-play');
|
|
};
|
|
$(this).find('i').removeClass('fa-play');
|
|
$(this).find('i').addClass('fa-pause');
|
|
$(this).attr('status', 'playing');
|
|
}
|
|
return false;
|
|
})
|
|
</script> |