none
Problem with multiple MediaElement on one page

    General discussion

  • hi, when i try to using multiple mediaelement on one page. i have trouble, only 1 mediaelement which can play,

    this my .cs code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Microsoft.Phone.Controls;
    
    namespace colour_apps
    {
        public partial class MainPage : PhoneApplicationPage
        {
            // Constructor
            public MainPage()
            {
                InitializeComponent();
            }
    
    
            private void StopAll()
            {
                soundBlue.Stop();
                soundGreen.Stop();
                soundIndigo.Stop();
                soundRed.Stop();
                soundYellow.Stop();
                soundBlack.Stop();
            }
    
            private void btnRed_Click(object sender, RoutedEventArgs e)
            {
                StopAll();
                soundRed.Play();
                
            }
    
            private void btnYellow_Click(object sender, RoutedEventArgs e)
            {
                StopAll();
                soundYellow.Play();
            }
    
            private void btnBlack_Click(object sender, RoutedEventArgs e)
            {
                StopAll();
                soundBlack.Play();
            }
    
            private void btnBlue_Click(object sender, RoutedEventArgs e)
            {
                StopAll();
                soundBlue.Play();
            }
    
            private void btnIndigo_Click(object sender, RoutedEventArgs e)
            {
                StopAll();
                soundIndigo.Play();
            }
    
            private void btnGreen_Click(object sender, RoutedEventArgs e)
            {
                StopAll();
                soundGreen.Play();
            }
    
            private void soundYellow_MediaOpened(object sender, RoutedEventArgs e)
            {
    
            }
        }
    }


    this .xaml code:

    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
                <!--Suara Binantang-->
                <MediaElement x:Name="soundRed" Source="sounds/red.mp3" AutoPlay="False"  Volume="1"/>
                <MediaElement x:Name="soundYellow" MediaOpened="soundYellow_MediaOpened" Source="sounds/yellow.mp3"  Volume="1"/>
                <MediaElement x:Name="soundBlack" Source="sounds/black.mp3" AutoPlay="False" Volume="1"/>
                <MediaElement x:Name="soundBlue" Source="sounds/blue.mp3" AutoPlay="False" Volume="1"/>
                <MediaElement x:Name="soundIndigo" Source="sounds/indigo.mp3" AutoPlay="False" Volume="1"/>
                <MediaElement x:Name="soundGreen" Source="sounds/green.mp3" AutoPlay="False" Volume="1"/>
                
                
                <Button x:Name="btnRed" Height="160" HorizontalAlignment="Left"  VerticalAlignment="Top" Width="213" Margin="9,6,0,0"  Background="Red" Click="btnRed_Click"/>
    
                <Button x:Name="btnYellow" Height="160" HorizontalAlignment="Left" Margin="234,6,0,0"  VerticalAlignment="Top" Width="213"  Background="Yellow" Click="btnYellow_Click"/>
        
                <Button x:Name="btnBlack" Height="160" HorizontalAlignment="Left" Margin="9,198,0,0" VerticalAlignment="Top" Width="213" Background="Black" Click="btnBlack_Click"/>
                        
                <Button x:Name="btnBlue" Height="160" HorizontalAlignment="Left" Margin="234,198,0,0"  VerticalAlignment="Top" Width="213" Background="Blue" Click="btnBlue_Click"/>
            
                <Button x:Name="btnIndigo" Height="160" HorizontalAlignment="Left" Margin="9,396,0,0"  VerticalAlignment="Top" Width="213" Background="Indigo" Click="btnIndigo_Click"/>
                    
                <Button x:Name="btnGreen" Height="160" HorizontalAlignment="Left" Margin="234,396,0,0"  VerticalAlignment="Top" Width="213" Background="Green" Click="btnGreen_Click"/>
                    
            </Grid>
        </Grid>

    so, please help me to solved this problem ;) thanks
    Wednesday, October 12, 2011 6:43 AM