0

我正在使用此代码制作一个播放列表,将在其中播放来自 youtube 的视频,但我无法突出显示正确的曲目,因为它在 youtube 播放列表中我将如何编辑代码以实现此功能?

function addToplaylist(title)
{
    window.title= title;
    $("#video").html('<img src="/img/24.gif">');
    $.ajax({
        type: "POST",
        url: '/includes/ajax.php',
        data: {title: title},
        success: function(result) {
            var playlist = $.cookie('playlist');

            if (playlist!=null && playlist!="") {
                $.cookie("playlist", playlist+','+result, { expires: 500, path: '/' });
                var playlistt = $.cookie('playlistt');
                var cookie = playlistt+','+window.title;
                $.cookie("playlistt", cookie, { expires: 500, path: '/' });
                $("#video").html('<div style="left:5px;position:relative;width:99%;height:29px;overflow:hidden;float:left;"><div style="position:absolute;top:-273px;left:-3px"><iframe width="690" height="300" src="https://www.youtube.com/embed/' +result+ '/?autoplay=1&playlist=' +playlist+'&rel=0"></iframe></div>');
            } else {
                $.cookie("playlist", result, { expires: 500, path: '/' });
                var playlistt = $.cookie('playlistt');
                $.cookie("playlistt", window.title, { expires: 500, path: '/' });
                var cookie = window.title;
                $("#video").html('<div style="left:5px;position:relative;width:99%;height:29px;overflow:hidden;float:left;"><div style="position:absolute;top:-273px;left:-3px"><iframe width="690" height="300" src="https://www.youtube.com/embed/' +result+ '/?autoplay=1&rel=0"></iframe></div>');
           }

            var playlistts=cookie.split(",");
            document.getElementById("player").style.display = 'block';

            $("#close").html('<a class="icon-remove" title="Close Player"></a>');
            $("#drop").html('<div class="btn-group plinfo"><div class="btn btn-inverse">'+playlistts.length+' Tracks In Playlist</div><div onclick="dropPlaylist()" class="btn btn-inverse" title="Cleanup Playlist">Cleanup Playlist</div></div>');
            $("#drag").html('<a class="icon-move" style="cursor:move;" title="Drag Player"></a>');

            var each = playlistts.join('</span><li><img class="plimg" onload="this.src = \'/includes/image.php?\'+$(this).next(\'span.titletrack\').text()" src="/img/cover.png"><span  onclick="playinToplaylist($(this).html());" class="titletrack">');
             $("#playlist").html('<li><img src="/img/cover.png"><span  onclick="playinToplaylist($(this).html());" class="titletrack">' + each);

            var divCollection = document.getElementsByClassName("playlist");
            for (var i = 0; i < divCollection[0].childElementCount; i++) {
                if (divCollection[0].children[i].textContent == window.title) {
                findMeText = divCollection[0].children[i];
                window.setTimeout(function() { findMeText.style.background = '#aaa'; }, 0);
                window.setTimeout(function() { findMeText.style.background = '#000'; }, 3000);
                }
            }
        }
    }); 
}
4

0 回答 0