locked
problem in play/call media element sound RRS feed

  • Question

  • I create usercontrol name it Audio_Play..

    and the code in Audio_Play.xaml.cs is :


    private int _count = 8;

            // MediaElement
            private int _index = 0;

            public AudioPlayer()
            {
                InitializeComponent();

                this.Loaded += new RoutedEventHandler(AudioPlayer_Loaded);
            }

            void AudioPlayer_Loaded(object sender, RoutedEventArgs e)
            {
                for (int i = 0; i < _count; i++)
                {
                    var element = new MediaElement();
                    element.Volume = 0.7d;

                    root.Children.Add(element);
                }
            }


    private void Play(string address)
            {
                if (_index > _count - 1)
                    _index = 0;

                var element = root.Children[_index] as MediaElement;
                element.Source = new Uri(address, UriKind.Relative);
                element.Stop();
                element.Play();

                _index++;
            }


            public void PlayDrop()
            {
                Play("/Skrip;component/Resources/over.mp3");
            }


            public void PlayEat()
            {
                Play("/Skrip;component/Resources/eat.mp3");
            }

            public void PlaySkin()
            {
                Play("/Skrip;component/Resources/skin.mp3");
            }

            public void PlayOver()
            {
                Play("/Skrip;component/Resources/over.mp3");
            }

    }


    then i describe it in Main.xaml

    behind Main.xaml.cs I call  PlayDrop(), PlayEat(), PlaySkin(), PlayOver(), when some action on going. But it's not working.. how to fix it.?


    and I create some action with usercontrol main.xaml, in this main.xaml.cs I create Boolean to give Enabled = false (the coding behind isnot running/Stop), and Enabled = true (the coding behind it is running)..=>> (Stop and Play the action in main.xaml). In center action I call other usercontrol and name it soal.xaml

    I stop main.xaml : main.Enabled = false, then call soal.xaml, => i doit with "if"

    then when soal.xaml visibility is collapsed, main.xaml is start again. main.enabled = true. continuing the previous action. I can't coding it..


    many thanks..



    Sunday, August 15, 2010 9:29 AM

Answers

  • Hi Dwi,

    Firstly, my test shows that there is no Enabled property with MediaElement.  We can call Stop function instead.  

    Secondly, for not working, please double check video source is correct.  As a test, you can add it to ClientBin and you can call it like this.  Play("over.wmv");

    http://forums.silverlight.net/forums/t/130058.aspx

    Finally, please check whether your video is ok.  Sometimes, a video won't work even though it has a "wmv" extension.

    Best regards,

    Jonathan

    Wednesday, August 18, 2010 4:45 AM