简体   繁体   English

我的jplayerplaylist删除功能不起作用

[英]My jplayerplaylist remove function isn't working

I'm trying to make a mobile version of my site, and the jplayer functionality closely resembles that of my main site. 我正在尝试制作网站的移动版本,并且jplayer功能与我的主网站非常相似。 The playlist is updated depending on which page you are on, and all the songs except the one you are currently listening to are deleted from the playlist, then the page dynamically adds songs from the page you are viewing. 播放列表会根据您所在的页面进行更新,并且将从播放列表中删除当前正在听的歌曲(当前正在听的歌曲除外)中的所有歌曲,然后页面会从正在查看的页面中动态添加歌曲。

It works fine on my main page, but my mobile version (which is almost the same code), does not work on. 它可以在我的主页上正常工作,但是我的移动版本(几乎相同的代码)无法使用。

I set jplayer_playlist.option("removeTime", 0); 我设置了jplayer_playlist.option("removeTime", 0); just like the jplayer documentation suggests, but it doesn't work. 就像jplayer文档建议的那样,但是它不起作用。 Here is a bit of my code so you can see exactly what I'm doing. 这是我的一些代码,因此您可以确切地看到我在做什么。

    function reload()
    {
        var current = jplayer_playlist.current;

        for(var i = 0; i < current; i++)
        {
            deleteSong(0);
        }
        var length = theTitles.length;
        for(var i = 0; i < (length - 1); i++)
        {
            deleteSong(1);
        }
    }

    function deleteSong(index)
    {
        if(!jplayer_playlist.remove(index))
        {
            console.log("Could not delete it.");
        }
    }

The first delete does not show the error message, but the second (and every delete after) does. 第一个删除不显示错误消息,但是第二个(以及之后的每个删除)显示错误消息。 It seems as though it is not recognizing that I set the removeTime to 0, even though I did (and before any delete calls were made). 似乎好像没有意识到我将removeTime设置为0,即使我这样做了(并且在进行任何删除调用之前)。 Is there anything else that the jplayer.remove function depends on when you are trying to delete something from it besides removeTime? 当您尝试从remove中删除某些东西时,jplayer.remove函数还有其他依赖吗?

I had the same problem and found an answer in jPlaylist docs: http://jplayer.org/latest/demo-02-jPlayerPlaylist/ 我遇到了同样的问题,并在jPlaylist文档中找到了答案: http ://jplayer.org/latest/demo-02-jPlayerPlaylist/

"Because the second command will only work if the remove animation time, removeTime, is zero." “因为第二个命令仅在删除动画时间removeTime为零时才有效。”

In my case, I coded the following feature to erase all the songs up to the current one: 就我而言,我编码了以下功能,以擦除所有歌曲直到当前的歌曲:

When creating the jPlaylist: 创建jPlaylist时:

var playlistOptions = {
playlistOptions: {
    enableRemoveControls: true,
    autoPlay: false,
    removeTime: 0
},
...
};
playlist = new jPlayerPlaylist(.......);

And the function that erases the songs: 以及删除歌曲的功能:

function deleteUpToCurrent(e) {
    while(playlist.current != 0) {
        playlist.remove(0); 
    }
    return false;
}

Hope it helps! 希望能帮助到你! Cheers 干杯

On line 355 of jquery.playlist.js in the jplayerPlaylist.remove function, there is a call to JQuery's remove function: 在jplayerPlaylist.remove函数的jquery.playlist.js的355 中,有一个对JQuery的remove函数的调用:

$(this).remove();

If you look in the source of JQuery, this is delegated to the DOM method 如果您查看JQuery的源代码 ,它将被委托给DOM方法

elem.parentNode.removeChild( elem );

In modern browsers, this DOM operation is asynchronous, ie it returns immediately but actually removing the DOM element takes time. 在现代浏览器中,此DOM操作是异步的,即,它立即返回,但实际上删除DOM元素需要花费时间。 Therefore the jplayerPlaylist.remove() method returns before the node has actually been removed. 因此,jplayerPlaylist.remove()方法在实际删除节点之前返回。 Unfortunately, there is no callback. 不幸的是,没有回调。 So the only workaround is a setTimeout. 因此,唯一的解决方法是setTimeout。

var DELAY = 10;
function reload()
{
    var current = jplayer_playlist.current;
    var length = jplayer_playlist.playlist.length;
    if (current > 0)
        deleteSong(0);
    else if (length > 1)
        deleteSong(1);
    if (length > 1)
        window.setTimeout(reload, DELAY);
}

You may have to adjust DELAY. 您可能需要调整延迟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM