Reputation: 284
I have a MediaElement playing(trying to play) a sound clip from within a storyboard. When I use an absolute path to the sound file (i.e c:\file\location\alarm.wave), it works fine. However, if I use a relative uri, it no workie.
I have my alarm.wav in a folder named Resources, that's in my project root. I've tried setting the alarm.wav Build Action to Content, Resource, and Embedded Resource. I've also added it in my Resources.resx. I've tried a number of relative URI's, such as /Resources/alarm.wav and Resources/alarm.wav and pack://application:,,,/Capricorn2;component/Resources/alarm.wav.
None of those combinations work...so I must be missing something obvious here...any thoughts?
<ListBox.ItemTemplate >
<DataTemplate>
<DataTemplate.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding IsAlarming}" Value="True"/>
<Condition Binding="{Binding IsAudioAlarm}" Value="True"/>
</MultiDataTrigger.Conditions>
<MultiDataTrigger.EnterActions>
<BeginStoryboard x:Name="soundPlayer">
<Storyboard>
<MediaTimeline Source="/Capricorn2;component/Resources/alarm.wav" Storyboard.TargetName="alarmSound" RepeatBehavior="Forever"/>
</Storyboard>
</BeginStoryboard>
</MultiDataTrigger.EnterActions>
<MultiDataTrigger.ExitActions>
<RemoveStoryboard BeginStoryboardName="soundPlayer"/>
</MultiDataTrigger.ExitActions>
</MultiDataTrigger>
</DataTemplate.Triggers>
<Border >
<Grid >
<MediaElement x:Name="alarmSound"/>
</Grid>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
Upvotes: 1
Views: 740
Reputation: 63
A relative URI wouldn't have '/' in front of it. So if your sound file's absolute path is
/ProjectName/Resources/alarm.wav
its relative path is then
Resources/alarm.wav
Upvotes: 1