javascript - 使用audioplayer.js,想通过使用控件播放下一首轨道

标签 javascript jquery audio

我有一个 Accordion 和上面的音频。我想控制下一个/上一个。去上类。现在单击 $(this) 选项卡切换,但另一个未打开且下一个轨道未播放。;( 当按下一个/上一个控件想要打开下一个 Accordion 并播放轨道时。 这是我的 Accordion JS 代码:

  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');
  });

切换下一首轨道:

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/ - 示例在这里

最佳答案

编辑
(删除了我的第一个答案...测试了这个。有效!;))

$(".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.
    }
});

我重命名了您的 next var,因为这很令人困惑。

关于javascript - 使用audioplayer.js,想通过使用控件播放下一首轨道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37597731/

相关文章:

javascript - 为什么我生成的图像没有根据我的鼠标光标设置它们的位置?

javascript - 将原始字符串更改为字符串对象引用

javascript - Angular 绑定(bind)事件

jquery - 使用 jquery 显示/隐藏行

java - 使用java的音频处理

python - audioop的 "sound fragment"参数是什么类型的文件?

javascript - 检查所选元素是否包含属性

javascript - Spring MVC JavaScript

javascript - AngularJS:将数据绑定(bind)到动态创建的 HTML

c# - 修剪 wav 文件