0

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?

Nick
  • 4,787
  • 2
  • 18
  • 24
  • What type of media that you are playing? The document also mentioned that `The system will use provided metadata in MP3 or AAC encoded files to determine the delay or padding compensation needed for gapless playback. If the MP3 or AAC encoded files don't provide this metadata, then the system determines the delay or padding heuristically.` – Roy Li - MSFT Jul 04 '22 at 06:15
  • It is M4A. Still, according to the documentation, padding will be provided only if available in the metadata of the file. Now, I always get a gap, though I shouldn't. I believe the gap is caused because of a delay while opening the stream and buffering the next song. – Nick Jul 04 '22 at 07:54

1 Answers1

0

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.

Nick
  • 4,787
  • 2
  • 18
  • 24