question

LakesideKnight-0651 avatar image
0 Votes"
LakesideKnight-0651 asked ·

When I use WPF MediaElement loaded a https mp3 resource,and call Play(),error appeared

When I use WPF MediaElement loaded a https mp3 resource,and call Play(),error appeared
(when load a http mp3 resource, nothing happened)
test link:
https://lgresv57.obs.cn-south-1.myhuaweicloud.com/lgRs/5cb46c128156422a97686475b0b645e5/dae926d641e143d79c1a4690bf0149a1.mp3
9041-ec3b2809-14ad-4ac2-9a16-680ee32a0c21.png


windows-wpf
· 1
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The MediaElement control in WPF often encounters this error when the source using https, you could get this mp3 stream to local to play it. There is also a thread which is related to yours question for you to refer to.


1 Vote 1 ·

1 Answer

PeterFleischer-3316 avatar image
1 Vote"
PeterFleischer-3316 answered ·

Hi, mediaelement in WPF does not have support to play audio/video stream. Download stream to local file like this:

   WebClient client = new WebClient();
   string url = @"https://lgresv57.obs.cn-south-1.myhuaweicloud.com/lgRs/5cb46c128156422a97686475b0b645e5/dae926d641e143d79c1a4690bf0149a1.mp3";
   client.DownloadFile(url,@"c:\temp\x.mp3");
   Uri path = new Uri(@"c:\temp\x.mp3");
   MediaPlayer me_media = new MediaPlayer();
   me_media.Open(path);
   me_media.Play();


· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks a lot. But we have mp4 resources either, it maybe not a perfect solution.
I gonna try vlc then.

0 Votes 0 ·