Ejemplo n.º 1
0
        public async override void play(bool alone)
        {
            try
            {
                setStemSounds();
                string soundResult = propStemSounds[(propValue / 10) - 1];
                if (alone == false)
                {
                    soundResult = propStemSounds[9 + (propValue / 10) - 1];
                }

                if (player == null)
                {
                    player = player ?? new MediaPlayer();
                }
                else
                {
                    player.Reset();
                }

                new System.Threading.Thread(async() => {
                    await player1.SetDataSourceAsync(soundResult);

                    player1.Prepare();
                    player1.Start();
                }).Start();

                byte[] TotalBytes  = System.IO.File.ReadAllBytes(soundResult);
                double bitrate     = (BitConverter.ToInt32(new[] { TotalBytes[28], TotalBytes[29], TotalBytes[30], TotalBytes[31] }, 0) * 8);
                double duration    = (TotalBytes.Length - 8) * 8 / bitrate;
                int    durationInt = Convert.ToInt32(duration * 1000);
                System.Threading.Thread.Sleep(durationInt);

                if (player1 == null)
                {
                    player1 = player1 ?? new MediaPlayer();
                }
                else
                {
                    player1.Reset();
                }

                await player.SetDataSourceAsync(soundResult);

                //player.Prepare();
                //player.Start();
            }
            catch (Exception e)
            { }
        }