Note that there are some explanatory texts on larger screens.

plurals
  1. POWindows Phone sound play
    primarykey
    data
    text
    <p>I have a lot of <code>.wav</code> files to play and because of that i created <code>AudioItem</code> class:</p> <pre><code>public class AudioItem { public string SongName { get; set; } public string SongText { get; set; } public AudioItem() { } /// &lt;summary&gt; /// Initialize AudioItem class /// &lt;/summary&gt; /// &lt;param name="SongName"&gt;The name of the song(with .wav)&lt;/param&gt; /// &lt;param name="SongText"&gt;Text to display&lt;/param&gt; public AudioItem(string SongName, string SongText) { this.SongName = SongName; this.SongText = SongText; } public void Play() { var stream = TitleContainer.OpenStream("Sound/" + SongName); var effect = SoundEffect.FromStream(stream); FrameworkDispatcher.Update(); effect.Play(); } } </code></pre> <p>In the view i have a <code>Listbox</code> of items:</p> <pre><code>&lt;ListBox Name="soundtrackLbx"&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Button Name="ListButton" HorizontalAlignment="Stretch" &gt; &lt;Button.Content&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;Image Margin="10" Height="30" Width="30" Source="Picture/audio.png"/&gt; &lt;TextBlock Margin="10" HorizontalAlignment="Stretch" Text="{Binding SongText}" FontFamily="Verdana" Tap="TextBlock_Tap" /&gt; &lt;/StackPanel&gt; &lt;/Button.Content&gt; &lt;/Button&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; </code></pre> <p>my code behind:</p> <pre><code>public ObservableCollection&lt;AudioItem&gt; AudioItems { get; set; } public MainView() { InitializeComponent(); AudioItems = new ObservableCollection&lt;AudioItem&gt;(); Initialize(); this.soundtrackLbx.ItemsSource = AudioItems; } private void Initialize() { AudioItems.Add(new AudioItem("ApsolutnoDa.wav", "Apsolutno da")); AudioItems.Add(new AudioItem("Da.wav", "Da")); } private void TextBlock_Tap(object sender, GestureEventArgs e) { TextBlock tblock = sender as TextBlock; string text = tblock.Text; AudioItem item = AudioItems.SingleOrDefault(a =&gt; a.SongText == text); item.Play(); } </code></pre> <p>well, it happens that <code>.wav</code> sometimes i hear them play, and sometimes i don't, and i have no clue why is that.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload