chnage audio src并播放新音频

时间:2018-08-08 07:05:54

标签: jquery html audio

我已更改音频src,并在单击标记(i)类(playbtn)时播放了新的src,但对我不起作用! 您能帮我解决这个问题吗?

   <table class="table table-striped table-dark">
                        <thead>
                        <tr>
                            <th scope="col">play</th>
                            <th scope="col">musicname</th>
                            <th scope="col">download</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <th scope="row"><i class="playbtn" id="plone"></i></th>
                            <td>first music</td>
                            <td><a href="pishro.mp3" class="dlfile" id="audioone"><div class="dalbumhov"><i class="download-album"></i></div></a></td>
                        </tr>
                        <tr>
                            <th scope="row"><i class="playbtn" id="pltwo"></i></th>
                            <td>two music</td>
                            <td><a href="tohi.mp3" class="dlfile" id="audiotwo"><div class="dalbumhov"><i class="download-album"></i></div></a></td>
                        </tr>
                        <tr>
                            <th scope="row"><i class="playbtn" id="pltree"></i></th>
                            <td>tree music</td>
                            <td><a href="yeganeh.mp3" class="dlfile" id="audiotree"><div class="dalbumhov"><i class="download-album"></i></div></a></td>
                        </tr>
                        <tr>
                            <th scope="row"><i class="playbtn" id="plfor"></i></th>
                            <td>for music</td>
                            <td><a href="tataloo.mp3" class="dlfile" id="audiofor"><div class="dalbumhov"><i class="download-album"></i></div></a></td>
                        </tr>

                        </tbody>
                    </table>

这是我的jquery代码,用于更改音频src并播放

    $(".playbtn").click(function() {

        var source = $('#audioone').attr('href');
        var audio = $('#mp3Source').attr('src');
        $("#mp3Source").attr("src", source);
        var audiochange = $('#mp3Source').attr('src');

    if(audiochange == source){
    $( ".audioplayer-playpause" ).click();
    }

});

这是我的音频代码

    <audio preload="auto" controls class="play"  id="audio_core">
                    <source src="" id="mp3Source">
                </audio>

谢谢

0 个答案:

没有答案