pwnz22 pwnz22 - 6 months ago 35
jQuery Question

Using audioplayer.js, want to play next track by using controls

I have an accordion and audios on it. I want to make controls the next/prev. to get work. Now on click the

$(this)
tab toggling but the other is not opening and the next track is not playing.;( When pressing the next/prev controls want to open the next accordion and play track.
Here is my JS code for accordion:

var next = jQuery('.my_music').find('.accordion-toggle');
next.click(function(){
jQuery(this).next().slideToggle('fast');
jQuery(".accordion-content").not(jQuery(this).next()).slideUp('fast');
});


For switching next track:

jQuery('.next_music').click(function(){
// jQuery(next).next().slideToggle('fast');
// cl(this);
jQuery(".accordion-content").not(jQuery(this).next()).slideUp('fast');
});


https://www.bessetteweb.com/valjion/ - example here

Answer

EDIT
(Removed my first answer... Tested this one. Workings! ;) )

$(".next_music").click(function(){
    var actualAccordion = $(this).parent().parent().parent('.accordion-content');
    console.log("next clicked");


    // find the accordion below by getting it's parent's next element (".my_music_wrap").
    belowAccordion = actualAccordion.parent().next().children('.accordion-toggle').first();

    // Toggle it!
    if(belowAccordion.length>0){    // If an accordion is found
        actualAccordion.first().slideToggle('fast');    // Toggles actual accordion.
        belowAccordion.click()  //.slideToggle('fast');
        belowAccordion.next().first().children().children().children().children(".audioplayer-playpause").click();
    }else{
        alert('No other song to play!');    //Will happen on the next button of the fifth song.
    }
});



$(".prev_music").click(function(){
    var actualAccordion = $(this).parent().parent().parent('.accordion-content');
    console.log("prev clicked");


    // find the accordion below by getting it's parent's next element (".my_music_wrap").
    aboveAccordion = actualAccordion.parent().prev().children('.accordion-toggle').first();

    // Toggle it!
    if(aboveAccordion.length>0){    // If an accordion is found
        actualAccordion.first().slideToggle('fast');    // Toggles actual accordion.
        aboveAccordion.click()  //.slideToggle('fast');
        aboveAccordion.next().first().children().children().children().children(".audioplayer-playpause").click();
    }else{
        alert('No other song to play!');    //Will happen on the prev button of the first song.
    }
});

I renamed your next var, since was confusing.