Reading mediaPlayerCreate.MediaPlayer.PlaybackSession.Position gives error when playback is paused #2408
Labels
Pri2
Topic is in the second 25% of page views for the repo.
uwp/prod
Topic product is UWP-related.
winrt-reference/tech
Topic technology is WinRT-related.
Go a very strang bug with the MediaPlayer control. Application in C#/UWP.
Had code that worked perfectly for 2 years in production. Ran on Win10.
Upgraded tot Win11. Got an error in the code as described below:
I have a KeyUp event handler that check for hitting the spacebar. The spacebar acts as a toggle. Hitting it will toggle between play and pause of the MediaPlayer control. Control is display with manual controls (play/forward etc.) on it.
File is loaded in the control. Manual controls work fine.
Hitting space bar gives an error that the control displays on screen: cannot decode stream.
That in itself cannot be correct, because with manual control I can play the mp3 file.
I simplified the code to reproduce the bug. In the event handler I have this snipped.
if (mediaPlayerCreate.MediaPlayer.PlaybackSession.PlaybackState != MediaPlaybackState.Playing)
{
TimeSpan currentMediaPlayerPosition = mediaPlayerCreate.MediaPlayer.PlaybackSession.Position;
mediaPlayerCreate.MediaPlayer.Play();
}
this code will give the error.
Removing the line:
TimeSpan currentMediaPlayerPosition = mediaPlayerCreate.MediaPlayer.PlaybackSession.Position;
yields working code. (the Position is read a few ms later in the code, apparently it isn't a problem any more then)
In my opinion when the mediaplayer is paused it should be possible to read the position of the player, clearly doesn't work.
Target version: Windows 11 (10.0; Build 22000)
Min version: Windows 10, version 1809 (10.0; Build 17763)
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: