Baseflow / XamarinMediaManager

Cross platform Xamarin plugin to play and control Audio and Video
https://baseflow.com
MIT License
769 stars 306 forks source link

Calling 'playQueueItem' immediately after changing the queue doesn't play, immediately resets queue when play called again later #856

Open BenDTU opened 2 years ago

BenDTU commented 2 years ago

🐛 Bug Report

Running the latest version of XamarinMediaManager, loading a queue and playing a song in the queue other than the first one is not behaving as expected. Calling 'PlayQueueItem' changes the 'current' item but it does not play. Calling 'play' later causes the current item to reset back to the first item in the queue.

Expected behavior

I would assume 'PlayQueueItem' would immediately start playing the song in the location in the queue specified.

Reproduction steps

await CrossMediaManager.Current.Stop();            
CrossMediaManager.Current.Queue.Clear();
foreach (var item in mediaItemPlaylist)
{
    CrossMediaManager.Current.Queue.Add(item);
}
await CrossMediaManager.Current.PlayQueueItem(selectedSongIndex)

This will cause the current item to change but nothing will play. Calling CrossMediaManager.Current.Play() later will reset the queue.

Configuration

Xamarin.Forms 5.0.0.2337 Xamarin Essentials 1.7.1 Plugin.MediaManager 1.1.0

Version: 1.x

Platform:

BenDTU commented 2 years ago

Quick update - can confirm that this isn't an issue running on iOS.

Dirwaz commented 2 years ago

i am having the same issue on Android only. on iOS it is working fine.

SalimiHabib commented 2 years ago

same issue on android not playing

var inx = _mediaManager.Queue.IndexOf((IMediaItem)obj);
 var r = await _mediaManager.PlayQueueItem(inx);
Shrp77 commented 2 years ago

Same exact behavior on my end too (Android app)

arahmancsd commented 2 years ago

same here, I tried the overloaded PlayQueueItem with IMediaItem but it doesn't play the item specified in the queue. await CrossMediaManager.Current.PlayQueueItem(CrossMediaManager.Current.Queue.FirstOrDefault()); Change it to any item in the queue it doesn't work as expected.

janwiebe-jump commented 2 years ago

It might be caused by this line, but I'm unsure why: https://github.com/Baseflow/XamarinMediaManager/blob/develop/MediaManager/Platforms/Android/MediaManagerImplementation.cs#L300

The queue of the MediaController is empty at this point, so that's might be why it cannot jump to the specified queue item.

janwiebe-jump commented 2 years ago

@BenDTU What happens if you call an

await (MediaManagerBase)CrossMediaManager.Current).Play()

at the end?

This doesn't work for me.

I have no clue how to fix this, I hope someone else does, or has a workaround.

szurgot commented 1 year ago

Old issue, but I found it's due to the Transport Controls not being prepared.

https://github.com/Baseflow/XamarinMediaManager/blob/develop/MediaManager/Platforms/Android/MediaManagerImplementation.cs#L300

Adding this at line 302 fix it for me. if (this.IsStopped()) MediaController.GetTransportControls().Prepare();

arahmancsd commented 1 year ago

Old issue, but I found it's due to the Transport Controls not being prepared.

https://github.com/Baseflow/XamarinMediaManager/blob/develop/MediaManager/Platforms/Android/MediaManagerImplementation.cs#L300

Adding this at line 302 fix it for me. if (this.IsStopped()) MediaController.GetTransportControls().Prepare();

@szurgot Would you mind creating a PR for this, please?

szurgot commented 1 year ago

@arahmancsd Here's the PR to fix this issue. https://github.com/Baseflow/XamarinMediaManager/pull/910

BenDTU commented 4 months ago

I tried adding the above PR but it still didn't work, playing a queue and then trying to play an item in that queue still results in the first item being played.

Hardt-Coded commented 3 weeks ago

Same on my end. Fix doesn't work. Queue is playing the first time. After Pause and call PlayQueueItem(idx) again, nothing happens.