예제 #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < WaveIn.DeviceCount; i++)
            {
                inputList.Items.Add(WaveIn.GetCapabilities(i).ProductName);
            }
            if (inputList.Items.Count > 0)
            {
                inputList.SelectedIndex = 0;
            }
            for (int i = 0; i < WaveOut.DeviceCount; i++)
            {
                outputList.Items.Add(WaveOut.GetCapabilities(i).ProductName);
            }
            if (outputList.Items.Count > 0)
            {
                outputList.SelectedIndex = 0;
            }

            settings.Remotes.ReadXML(settings.PhonebookFilename);
            foreach (Remote remote in settings.Remotes)
            {
                comboBox1.Items.Add(remote.Name);
            }
            if (comboBox1.Items.Count > 0)
            {
                comboBox1.SelectedIndex = 0;
            }
            playersForm = new PlayersForm(new WaveFormat(48000, 16, 1));
        }
예제 #2
0
        public Player(string filename, WaveFormat format, PlayersForm form)
        {
            CallingForm   = form;
            GroupBox.Text = Path.GetFileName(filename);

            try
            {
                reader = new AudioFileReader(filename);
                if (format.Channels == 1)
                {
                    converter = new WdlResamplingSampleProvider(reader, format.SampleRate).ToMono().ToWaveProvider16();
                }
                else if (format.Channels == 2)
                {
                    converter = new WdlResamplingSampleProvider(reader, format.SampleRate).ToWaveProvider16();
                }
                clipBytes  = (int)(((double)converter.WaveFormat.AverageBytesPerSecond / (double)reader.WaveFormat.AverageBytesPerSecond) * reader.Length);
                clipBuffer = new byte[clipBytes];
                converter.Read(clipBuffer, 0, clipBytes);
                if (converter.WaveFormat.AverageBytesPerSecond != format.AverageBytesPerSecond)
                {
                    MessageBox.Show("Audio file is wrong format.  Should be " + format.ToString());
                    this.Dispose();
                    return;
                }
                audioPlayer = new WaveOutEvent();
                audioPlayer.Init(converter);
                Buffer = new BufferedWaveProvider(format);
                Buffer.BufferDuration          = reader.TotalTime;
                Buffer.DiscardOnBufferOverflow = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error loading audio file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Dispose();
            }
            GroupBox.Controls.Add(PlayButton);
            GroupBox.Controls.Add(DeleteButton);
            GroupBox.Controls.Add(UpButton);
            GroupBox.Controls.Add(DownButton);

            PlayButton.Click    += PlayButton_Click;
            DeleteButton.Click  += DeleteButton_Click;
            UpButton.Click      += UpButton_Click;
            DownButton.Click    += DownButton_Click;
            PlayButton.BackColor = Color.Green;
        }