Hi,
I’m trying to find out how to insert an element into a currently playing
playlist at a fixed (soft/hard) time.
My problem: Inserting an element creates a gap “Sendeloch” before the
inserted item. When the “Sendeloch” is played it turns into endless silence “Stille (unendlich)”.
This silence element now blocks a player untill I manually remove it.
Also the imported element itself doesn’t display the correct time length information
until I manually skip to it.
Screenshot/Code below - any idea what I’m doing wrong here?

// Insert Element at fixed time
var
i: integer;
iItemCount: integer;
st : string;
t1,t2 : TDateTime;
newItem: IPlaylistItem;
newItemIndex : integer;
activePlayer: integer;
activeItem: IPlaylistItem;
curpos: TTimeValue;
begin
// Generate a DateTime so use for a playlist item later
// Example 2011.02.05 at 11:00
t1 := now;
t1 := EncodeDate(2012, 2,5) + EncodeTime(11,0,0,0);
st := FormatDateTime('c', t1) ;
SystemLog('My time '+st);
// Create an empty container
// newItem = Factory.CreateContainerPlaylistItem;
if (not FileExists('c:\news\news.mp3')) then begin
SystemLog('Datei nicht gefunden.');
exit;
end;
newItem := Factory.CreateFilePlaylistItem('c:\news\news.mp3', []);
newItem.SetFixTime(t1)
newItem.SetTiming(timHard)
// Alternative: newItem.SetTiming(timSoft)
newItem.GetArtists.Clear;
newItem.GetArtists.Add('');
newItem.SetTitle('Die aktuellen Nachrichten');
newItem.SetItemType(pitNews); // TPlaylistItemType
iItemCount := CurrentPlaylist.GetCount;
SystemLog('Playlist einträge '+IntToStr(iItemCount));
CurrentPlaylist.BeginUpdate;
try
activePlayer := -1;
for i := 0 to CurrentPlaylist.GetPlayerCount - 1 do
if CurrentPlaylist.GetPlayer(i).GetState = psPlaying then begin
activePlayer := i;
break;
end;
if activePlayer = -1 then begin
SystemLog('No player is active!');
CurrentPlaylist.Insert(CurrentPlaylist.GetNextIndex, newItem);
// no need to call AutomationNext here
exit;
end;
// Index of item that is currently playing
activeItem := CurrentPlaylist.GetPlayer(activePlayer).GetItem;
NewItemIndex := 0
for i := CurrentPlaylist.IndexOf(activeItem) to CurrentPlaylist.GetCount- 1 do begin
t2 := CurrentPlaylist.GetStartTime(i ,sttCalculated)
If (t2 < t1) then
continue;
NewItemIndex := i;
break;
end;
// Insert new item below
CurrentPlaylist.Insert(NewItemIndex, newItem);
// CurrentPlaylist.SkipTo(newItem);
// CurrentPlaylist.AutomationNext
finally
CurrentPlaylist.EndUpdate;
end;
end.