Change Source in MediaElement (SILVERLIGHT)

I would like to change the song on my MediaElent from track1.mp3 to track2.mp3. And here is the code:

MyMediaElement.Stop();
Uri u = new Uri("track2.mp3", UriKind.Relative);
MyMediaElement.Source=u;
MyMediaElement.Play();

MediaElement changes source but does not start. What could be wrong with this code?

+3
source share
4 answers

Try setting MyMediaElement.AutoPlay to true, as soon as the source file changes, it should play. You can also explore using the MediaElement.SetSource () method, which accepts a stream, not a uri.

+5
source

. XAML, , , .
MediaOpened .
, Play() , . . , Play(); .

+2

, . , : -

track2 , ?

MediaFailed, ?

TextBlock CurrentState, , CurrentState.

+1

You install AutoPlayin false, and then in the MediaOpened handler you execute Play(). People kind of hinted at a solution here, but not very accurately. You can also handle the MediaFailed event in case the media does not open for any reason (file cannot be found, etc.).

0
source

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


All Articles