Answered by:
MediaElement not responding

Question
-
The sound keeps coming even after a pause or stop. I switch to a different flipview but sound keeps streaming?
Any ideas?
Keeps playing 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
I can't stop the sound coming from the media element that plays videos.
<FlipView
x:Name="FlipView2"
<FlipView.ItemTemplate>
<DataTemplate>
<Grid>
<MediaElement x:Name="VideoMediaElement"
Width="1200"
Height="600"
Source="{Binding VideoFileCustom}"
Stretch="Fill"
AreTransportControlsEnabled="False"
Loaded="VideoMediaElement_Loaded"
DoubleTapped="VideoMediaElement_DoubleTapped"
AutoPlay="True"
/>
// Now the code behind
MediaElement media = DefaultViewModel["VideoMediaElement"] as MediaElement;
await Window.Current.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
{
if (media.CurrentState == MediaElementState.Playing)
{
if (media.CanPause)
{
media.Pause();
}
else
{
media.Stop();
}
}
});
Bruno Terkaly
- Edited by BrunoTerkalyMicrosoft employee Thursday, December 26, 2013 10:54 PM
Thursday, December 26, 2013 10:53 PM
Answers
-
Hello Bruno,
Ynfortunately I can't give you a good diagnosis based on the code snippets that you have posted. It is possible that the instance you are manipulating in your worker thread does not match the instance that is playing. I'll contact you directly and we can work to debug your code.
Thanks,
James
Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/
- Marked as answer by James Dailey - MSFTMicrosoft employee, Moderator Friday, December 27, 2013 1:44 AM
Friday, December 27, 2013 1:44 AMModerator -
It turns out that there were multiple instances of the MediaElement control. So if you emebed a MediaElement within a FlipView and use binding for the "Source" property, multiple instances are present. This was some code that shut them all down.
Proposed solution 1
2
3
4
5
6
7
foreach (MediaElement el in mediaElements)
{
if (el.CurrentState == MediaElementState.Playing)
{
el.Stop();
}
}
Bruno Terkaly
- Marked as answer by James Dailey - MSFTMicrosoft employee, Moderator Friday, December 27, 2013 10:32 PM
Friday, December 27, 2013 4:50 AM
All replies
-
Hello Bruno,
Ynfortunately I can't give you a good diagnosis based on the code snippets that you have posted. It is possible that the instance you are manipulating in your worker thread does not match the instance that is playing. I'll contact you directly and we can work to debug your code.
Thanks,
James
Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/
- Marked as answer by James Dailey - MSFTMicrosoft employee, Moderator Friday, December 27, 2013 1:44 AM
Friday, December 27, 2013 1:44 AMModerator -
It turns out that there were multiple instances of the MediaElement control. So if you emebed a MediaElement within a FlipView and use binding for the "Source" property, multiple instances are present. This was some code that shut them all down.
Proposed solution 1
2
3
4
5
6
7
foreach (MediaElement el in mediaElements)
{
if (el.CurrentState == MediaElementState.Playing)
{
el.Stop();
}
}
Bruno Terkaly
- Marked as answer by James Dailey - MSFTMicrosoft employee, Moderator Friday, December 27, 2013 10:32 PM
Friday, December 27, 2013 4:50 AM