Using the WP8 emulator, I have Media Element (inside the Layout Root of my XAML file, so the element is part of the visual tree at runtime), and I'm trying to programmatically trigger it to play from the code behind.
I'm using the Caliburn Micro EventAggregator to send a message when something in my app's backend requires a sound to be played. In the view's code behind I'm using IHandle to set the media element's Source and trigger Play.
public void Handle(ToneMessage message)
{
MediaElem.Source = message.ToneUri;
MediaElem.Play();
}
When I trigger the message event, no sound is played. However, if I put a breakpoint on MediaElem.Play()
, when I step over it, the sound plays.
I don't know what's happening, basically my code works only when I'm stepping over it with the debugger. I'm still on the UI thread (even tried explicitly using the Dispatcher).
Any ideas are welcomed.