Example #1
0
        public SoundMain(Canvas container, string soundFile, int numBuffers, double loopTime)
        {
            _sounds = new List <SoundElement>();

            LoopTime = loopTime;
            Volume   = -1;

            // create the sound elements
#if SILVERLIGHT_PHONE
            // use XNA for sound - mixing is done for us
            Stream      stream = TitleContainer.OpenStream(soundFile);
            SoundEffect effect = SoundEffect.FromStream(stream);
            _effect = effect.CreateInstance();
            if (loopTime > 0)
            {
                _effect.IsLooped = true;
            }
#else
            // use MediaElement for Sound - one for each "buffer"
            for (int i = 0; i < numBuffers; i++)
            {
                _soundId++;

                // create the sound from XAML
                SoundElement theSound = new SoundElement();
                theSound.Sound.Volume = 0;
                if (loopTime <= 0)
                {
                    theSound.Sound.AutoPlay = true;
                }
                else
                {
                    // set this sound up to loop

                    theSound.Sound.AutoPlay = false;
                }
                theSound.Sound.Source = new Uri(soundFile, UriKind.Relative);
                string shortName = soundFile.Substring(soundFile.LastIndexOf("/") + 1, soundFile.LastIndexOf(".") - 1 - soundFile.LastIndexOf("/"));
                //theSound.Name = "sound" + shortName + _soundId.ToString();

                // add the sound to our List
                _sounds.Add(theSound);

                theSound.Sound.MarkerReached += new TimelineMarkerRoutedEventHandler(theSound_MarkerReached);
                theSound.Sound.MediaOpened   += new RoutedEventHandler(theSound_MediaOpened);
                theSound.Sound.MediaEnded    += new System.Windows.RoutedEventHandler(theSound_MediaEnded);

                // add the sound to our main page
                container.Children.Add(theSound.Sound);
            }
#endif
        }
        public SoundMain(Canvas container, string soundFile, int numBuffers, double loopTime)
        {

            LoopTime = loopTime;

            // create the sound elements


            _sounds = new List<SoundElement>();
            
            Volume = -1;

           // use MediaElement for Sound - one for each "buffer"
            for (int i = 0; i < numBuffers; i++)
            {
                _soundId++;
               
                // create the sound from XAML
                SoundElement theSound = new SoundElement();
                theSound.Sound.AutoPlay = false;

                theSound.Sound.Source = new Uri(container.BaseUri, soundFile);
                string shortName = soundFile.Substring(soundFile.LastIndexOf("/") + 1, soundFile.LastIndexOf(".") - 1 - soundFile.LastIndexOf("/"));
                //theSound.Name = "sound" + shortName + _soundId.ToString();

                // add the sound to our List
                _sounds.Add(theSound);

                theSound.Sound.MarkerReached += new TimelineMarkerRoutedEventHandler(theSound_MarkerReached);
                theSound.Sound.MediaOpened += new RoutedEventHandler(theSound_MediaOpened);

                // add the sound to our main page
                container.Children.Add(theSound.Sound);
            }
        }