Answer the question
In order to leave comments, you need to log in
Why does MediaElement's "Play()" method only work on button click?
Hello! I am developing a windows 8 application.
I have a MediaElement and a GridView. The GridView is bound to a collection of data.
I listen to the GridView.SelectionChanged event, set the Source for the MediaElement in it, then call the "Play" method. Music does not play. BUT: if you click on the button, when you click on which I also call the Play method, then everything is fine, the music is played. When calling Play from any other event handler, method, it also ignores everything and does not play (for example, when clicking on the "Next" button).
Am I doing something wrong? How to fix it?
Thanks in advance!
Answer the question
In order to leave comments, you need to log in
In such cases it is worth reading MSDN :)
Those. after setting the Source, subscribe to MediaOpened and already call Play() in the handler.
And it worked from the button, because while you were pressing the button, the file had time to open.
Look in which threads you call the play method. Try calling it on the UI thread
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question