dotnet / docs

This repository contains .NET Documentation.
https://learn.microsoft.com/dotnet
Creative Commons Attribution 4.0 International
4.27k stars 5.9k forks source link

MediaPlayer class has breaking changes from .NET 5 to 6 #27779

Closed skst closed 2 years ago

skst commented 2 years ago

The MediaPlayer class has breaking changes from .NET 5 (Windows.Media.Core.MediaPlayer) to .NET 6 (System.Windows.Media).

The class no longer implements these (and probably other) properties or methods.

MediaPlayer _player = new();
_player.AudioCategory = MediaPlayerAudioCategory.Alerts;
_player.AutoPlay = false;
_player.IsLoopingEnabled = false;
_player.Source = MediaSource.CreateFromUri(new Uri(PathSound));
_player.IsLoopingEnabled = repeatSound;
_player.CommandManager.IsEnabled = false;   // disable Windows media controls popup
_player.Dispose();

When the class is used to open a WAV or MP3 file and play it, the MediaFailed event is called with the "Windows Media Player version 10 or later is required." error message.

MediaPlayer _player = new();
_player.Open(new Uri(@"D:\OneDrive\Music\Pop\Rihanna\Loud (Explicit Version) [Explicit]\01-01- S&M.mp3"));
_player.Play();

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

skst commented 2 years ago

Windows.Media.Playback.MediaPlayer is the replacement, not System.Windows.Media.MediaPlayer.