Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

M3U and PLS lists are reverse played

Help
swerer
2006-03-27
2013-04-30
  • swerer
    swerer
    2006-03-27

    When I use IceGenerator with M3U or PLS playlists it plays songs from in the wrong order, the song are played from end of list to beginning. This is because of error in circular.cpp file. Error is in Insert (cDoubleLinkedItem *object) method of class cCircularList.
    The method is:
    void cCircularList::Insert(cDoubleLinkedItem *object)
    {
      if (Ptr == NULL)
      {
        Ptr = object;                // first element
        Ptr->ConnectAfter(Ptr);            // chain is closed in a loop
        Ptr->ConnectBefore(Ptr);
      }
      else
      {
        /* NOTE: it connects after Ptr */
        object->ConnectBefore(Ptr);            // link to upper object
        Ptr->GetNext()->ConnectBefore(object);    // lower object link
        object->ConnectAfter(Ptr->GetNext());    // link to lower object
        Ptr->ConnectAfter(object);            // upper object link
      }
    }

    but it must look like this:
    void cCircularList::Insert(cDoubleLinkedItem *object)
    {
      if (Ptr == NULL)
      {
        Ptr = object;                // first element
        Ptr->ConnectAfter(Ptr);            // chain is closed in a loop
        Ptr->ConnectBefore(Ptr);
      }
      else
      {
        /* NOTE: it connects after Ptr */
        object->ConnectBefore(Ptr);            // link to upper object
        Ptr->GetNext()->ConnectBefore(object);    // lower object link
        object->ConnectAfter(Ptr->GetNext());    // link to lower object
        Ptr->ConnectAfter(object);            // upper object link

        /* Comments from Ivan Edrennikov (edrennikov@gmail.com)
        Here must be this line added:
        Ptr = object;
        because Ptr points to the last element in the list, not first.
        So, when another 'object' is added, this object becomes the last,
        thus, we need to assign Ptr to 'object'.
        */
        Ptr = object; //add this line to avoid the bug with wrong order of playing the songs
      }
    }