0
私は同じcurrentTimeでサウンドを再生する前と後のミュージックプレーヤーで作業しています。.attr( 'song');同じですが、.attr( 'song');それはcurrentTimeを0にリセットする必要があります。これは同時にサウンドを再生するために働きますが、attrが異なる場合はリセットされません。ユーザーが "前"または "後"ボタンをクリックし、両方の曲.attr( 'song')== rockの場合、currentTimeを0にリセットしてはいけませんが、ボタンと.attr( 'song')をクリックすると、それは0song attrがcurrent_Timeを0にリセットしていない場合Jquery
JSFiddleにCURRENTTIMEを設定する必要が異なります。
https://jsfiddle.net/jeffd/z7uymp23/
HTML:
<div class="songtype">Rock <br> <div class="smallerthang"><strong>Steve Godsley</strong> by Boontango</div></div>
<div class="beforebutton player" key="rockbefore.mp3" song="rock"><span class="symbol"><i class="material-icons playbuttonyo">play_circle_filled</i></span> Before</div>
<div class="afterbutton player" key="rockafter.mp3" song="rock"><span class="symbol"><i class="material-icons playbuttonyo">play_circle_filled</i></span> After</div>
<div class="songtype">Rap <br> <div class="smallerthang"><strong>Million or More</strong> by China Fox, Superhype Mic, Warren 'Thir13een' Young, Nicolas BONNEYRAT</div></div>
<div class="beforebutton player" key="rapbefore.mp3" song="rap"><span class="symbol"><i class="material-icons playbuttonyo">play_circle_filled</i></span> Before</div>
<div class="afterbutton player" key="rapafter.mp3" song="rap"><span class="symbol"><i class="material-icons playbuttonyo">play_circle_filled</i></span> After</div>
jQueryの
window.nowplay=$(".player");
$(".player").on('click', function() {
var key = $(this).attr('key');
var song = $(this).attr('song');
window.nowplay = $(this);
window.nowplay2 = $(this);
EvalSound(this, key);
$(".player").not(this).removeClass("pause");
$(".player").not(this).children('.symbol').html("<i class='material-icons playbuttonyo'>play_circle_filled</i>");
nowplay.children('.symbol').html("<i class='material-icons playbuttonyo'>pause_circle_filled</i>");
nowplay.addClass("pause");
});
var thissound = new Audio();
var currentKey;
function EvalSound(el, key) {
thissound.addEventListener('ended', function() {
nowplay.children('.symbol').html("<i class='material-icons playbuttonyo'>play_circle_filled</i>");
});
thissound.addEventListener('pause', function() {
nowplay.removeClass("pause");
nowplay.children('.symbol').html("<i class='material-icons playbuttonyo'>play_circle_filled</i>");
});
thissound.addEventListener('loadstart', function() {
});
thissound.addEventListener('playing', function() {
nowplay.children('.symbol').html("<i class='material-icons playbuttonyo'>pause_circle_filled</i>");
});
var timenow = thissound.currentTime;
if (currentKey !== key) thissound.src = key;
currentKey = key;
//currentSong = song;
thissound.currentTime = timenow;
//if (song !== currentSong) thissound.currentTime = 0;
if (thissound.paused) thissound.play();
else thissound.pause();
currentPlayer = thissound;
}
代わりに(.ATTR 'の使用[' .DATA() '](https://api.jquery.com/jquery.data/))'と接頭辞 'key' 'song'属性は' data-' – zer00ne