I am trying to implement gapless media player. I create a list of MediaPlaybackItem's and add them to an instance of MediaPlaybackList. The media playback items are created for files, uploaded on a server, using MediaSource.CreateFromUri()
.
So far so good, but when I play the media, there is a clearly audible pause when playing transitions from one item to another. I want to avoid this.
According to the documentation:
Items in a MediaPlaybackList are rendered using gapless playback.
However, the gap is there. I tried to set 'MediaPlaybackList.MaxPrefetchTime' but it did nothing.
Is there a way I can implement gapless playing using MediaPlaybackList?
CodePudding user response:
Indeed, the gap was caused because of the delay while opening the stream of the next MediaPlaybackItem
from the Uri source.
What I did is to call OpenAsync()
on each media playback item before starting the player:
foreach (var item in mediaItems)
{
_ = item.Source.OpenAsync();
}
This is a oversimplified example, where I do not await the async methods and therefore do not trap potential errors. Since I do not want to have a delay while the songs are opened, the best way would be to make a list of all async methods, and wait for them using 'Task.WhenAll' in a separate task.