How to play local mp3 files using MediaElement

I am creating a simple media player with Silverlight 4 (C #). Now I am using MediaElement, but it gives me an error

error 4001: .... System.Collections.ListDictionaryInternal

Now this error occurs when I want to set the MediaElement source. Therefore, when the user clicks "Play", he sets the source of the first song.

Song s = afspeelijst.ElementAt(currentPlayingIndex);
media.Source = new System.Uri(s.FilePath);
media.Position = TimeSpan.Zero;
media.Play();

The following code also does not work, but it removes the error. But still, there is no sound: s

media.SetSource(new FileStream(s.FilePath, FileMode.Open));
+3
source share
3 answers

You might want to check out this code. It worked great for me :)

mediaElement1.LoadedBehavior = MediaState.Manual;
mediaElement1.Source = new Uri(@"D:/ExamplePath/myVideoFile.avi");
//@ means that the string behind is a path so / won't be 
//treated like a special character
mediaElement1.Play();
+1
source

Silverlight 4 ( , , ) . ( ).

- .

string path = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "test/song.mp3");


            media.SetSource(new FileStream(path, FileMode.Open));
            media.Position = TimeSpan.Zero;
            media.Play();

,

+2

. '' .

"" . Silverlight 4, http . ftp, ftp://user:pass@address/myVoicefile.snd,

.Net .

, html silverlight. /ClientBin -, .

0
source

Source: https://habr.com/ru/post/1779902/


All Articles