Skip to content

Commit

Permalink
fix: media not playing when launch from file (#535)
Browse files Browse the repository at this point in the history
* fix: media not playing when launch from file
try to play the media when the player is not initialized

* a more complete fix
  • Loading branch information
huynhsontung authored Jan 10, 2025
1 parent e3b7136 commit a4d197e
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions Screenbox.Core/ViewModels/MediaListViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,16 @@ public void Receive(MediaPlayerChangedMessage message)
{
async void SetPlayQueue()
{
ClearPlaylist();
await EnqueueAndPlay(_delayPlay);
if (_delayPlay is MediaViewModel media && Items.Contains(media))
{
PlaySingle(media);
await TryEnqueueAndPlayPlaylistAsync(media);
}
else
{
ClearPlaylist();
await EnqueueAndPlay(_delayPlay);
}
}

_dispatcherQueue.TryEnqueue(SetPlayQueue);
Expand Down Expand Up @@ -187,7 +195,15 @@ public async void Receive(PlayFilesMessage message)
// If there is only 1 file, play it immediately
// Avoid waiting to get all the neighboring files then play, which may cause delay
ClearPlaylist();
await EnqueueAndPlay(file);
if (_mediaPlayer == null)
{
_delayPlay = media;
}
else
{
await EnqueueAndPlay(file);
}

// If there are more than one item in the queue, file is already a playlist, no need to check for neighboring files
if (Items.Count > 1) return;

Expand Down Expand Up @@ -642,6 +658,12 @@ private async Task EnqueueAndPlay(object value)
}

// If playNext is a playlist file, recursively parse the playlist and enqueue the items
await TryEnqueueAndPlayPlaylistAsync(playNext ?? value);
}

private async Task TryEnqueueAndPlayPlaylistAsync(object value)
{
MediaViewModel? playNext = GetMedia(value);
PlaylistCreateResult? result = (value as PlaylistCreateResult) ?? await CreatePlaylistAsync(playNext ?? value);
if (result != null && !result.PlayNext.Source.Equals(playNext?.Source))
{
Expand Down

0 comments on commit a4d197e

Please sign in to comment.