Repository: xbmc/xbmc
File: xbmc/playlists/PlayList.cpp (C++)

Code before:
  data["position"] = pos;
  CServiceBroker::GetAnnouncementManager()->Announce(ANNOUNCEMENT::Playlist, "OnAdd", item, data);
}

void CPlayList::Add(const std::shared_ptr<CFileItem>& item, int iPosition, int iOrder)
{
  int iOldSize = size();
  if (iPosition < 0 || iPosition >= iOldSize)
    iPosition = iOldSize;
  if (iOrder < 0 || iOrder >= iOldSize)
    item->SetProgramCount(iOldSize);
  else
    item->SetProgramCount(iOrder);

  // increment the playable counter
  item->ClearProperty("unplayable");
  if (m_iPlayableItems < 0)
    m_iPlayableItems = 1;
  else
    m_iPlayableItems++;

  // set 'IsPlayable' property - needed for properly handling plugin:// URLs
  item->SetProperty("IsPlayable", true);

  // set 'BasePath' property - needed for properly handling browse for subtitles
  item->SetProperty("BasePath", m_strBasePath);

  //CLog::Log(LOGDEBUG,"{} item:({:02}/{:02})[{}]", __FUNCTION__, iPosition, item->GetProgramCount(), item->GetPath());
  if (iPosition == iOldSize)
    m_vecItems.push_back(item);
  else
  {
    ivecItems it = m_vecItems.begin() + iPosition;
    m_vecItems.insert(it, 1, item);
    // correct any duplicate order values
    if (iOrder < iOldSize)
      IncrementOrder(iPosition + 1, iOrder);
  }
  AnnounceAdd(item, iPosition);
}

void CPlayList::Add(const std::shared_ptr<CFileItem>& item)
{
  Add(item, -1, -1);
}

void CPlayList::Add(const CPlayList& playlist)
{
  for (int i = 0; i < playlist.size(); i++)
    Add(playlist[i], -1, -1);
}

Review comment (suggestion):
tested but there is a problem
the CPlayList::Add method is used also when playback starts, this cause to delete the "BasePath" property value:
<img width="705" height="84" alt="immagine" src="https://github.com/user-attachments/assets/f292da02-7b6c-464b-838d-31cfa1523f92" />

a solution could be
```suggestion
  if (!item->HasProperty("BasePath"))
    item->SetProperty("BasePath", m_strBasePath);
```

Code after:
  data["position"] = pos;
  CServiceBroker::GetAnnouncementManager()->Announce(ANNOUNCEMENT::Playlist, "OnAdd", item, data);
}

void CPlayList::Add(const std::shared_ptr<CFileItem>& item, int iPosition, int iOrder)
{
  int iOldSize = size();
  if (iPosition < 0 || iPosition >= iOldSize)
    iPosition = iOldSize;
  if (iOrder < 0 || iOrder >= iOldSize)
    item->SetProgramCount(iOldSize);
  else
    item->SetProgramCount(iOrder);

  // increment the playable counter
  item->ClearProperty("unplayable");
  if (m_iPlayableItems < 0)
    m_iPlayableItems = 1;
  else
    m_iPlayableItems++;

  // set 'IsPlayable' property - needed for properly handling plugin:// URLs
  item->SetProperty("IsPlayable", true);

  // set 'BasePath' property - needed for properly handling browse for subtitles
  if (!item->HasProperty("BasePath"))
    item->SetProperty("BasePath", m_strBasePath);

  //CLog::Log(LOGDEBUG,"{} item:({:02}/{:02})[{}]", __FUNCTION__, iPosition, item->GetProgramCount(), item->GetPath());
  if (iPosition == iOldSize)
    m_vecItems.push_back(item);
  else
  {
    ivecItems it = m_vecItems.begin() + iPosition;
    m_vecItems.insert(it, 1, item);
    // correct any duplicate order values
    if (iOrder < iOldSize)
      IncrementOrder(iPosition + 1, iOrder);
  }
  AnnounceAdd(item, iPosition);
}

void CPlayList::Add(const std::shared_ptr<CFileItem>& item)
{
  Add(item, -1, -1);
}

void CPlayList::Add(const CPlayList& playlist)
{
  for (int i = 0; i < playlist.size(); i++)
    Add(playlist[i], -1, -1);