Exemplo n.º 1
0
        static void Main(string[] args)
        {
            MediaFoundationReader reader = new MediaFoundationReader(@"C:\Users\Null\Desktop\Disconnected - Pegboard Nerds.mp3");
            WaveOut wout = new WaveOut();

            wout.Init(reader);
            wout.Play();

            Console.Write("Input file path: ");
            player = new MciPlayer(Console.ReadLine().Trim('"'));
            player.Open();
            player.Play();

            MciSendString($"set {player.AliasName} time format msf", null, 0, IntPtr.Zero);
            Console.WriteLine($"Device Alias Name: {player.AliasName}");
            Console.WriteLine($"Length: {player.GetLength()}; Position: {player.GetPosition()}");

            string rst    = new string('\0', 256);
            string before = string.Copy(rst);
            int    err;

            while (true)
            {
                if ((err = MciSendString(Console.ReadLine(), rst, rst.Length, IntPtr.Zero)) != 0)
                {
                    Console.WriteLine($"Execute failed. {new MciException(err)}");
                }
                if (rst != before)
                {
                    Console.WriteLine($"Return text: {rst.TrimEnd('\0')}");
                    rst    = new string('\0', 256);
                    before = string.Copy(rst);
                }
            }
        }
Exemplo n.º 2
0
        private void trackBar2_MouseUp(object sender, MouseEventArgs e)
        {
            if (CheckStringItem(listBox1.SelectedItem, out string path))
            {
                if (musics.TryGetValue(path, out object playerObj))
                {
                    Type playerType = playerObj.GetType();

                    if (playerType == typeof(SoundPlayer))
                    {
                        //SoundPlayer player = (SoundPlayer)playerObj;

                        //player.Stop();
                    }
                    else if (playerType == typeof(MciPlayer))
                    {
                        MciPlayer player = (MciPlayer)playerObj;
                        player.Seek(trackBar2.Value);
                        player.Play();
                    }
                    else if (playerType == typeof(WaveOut))
                    {
                        //WaveOut player = (WaveOut)playerObj;
                        //player.Stop();
                    }
                }
            }
        }
Exemplo n.º 3
0
        void RemoveMusic(string path)
        {
            if (musics.TryGetValue(path, out object playerObj))
            {
                Type playerType = playerObj.GetType();

                if (playerType == typeof(SoundPlayer))
                {
                    SoundPlayer player = (SoundPlayer)playerObj;
                    player.Stop();
                    player.Dispose();
                }
                else if (playerType == typeof(MciPlayer))
                {
                    MciPlayer player = (MciPlayer)playerObj;
                    player.Pause();
                    player.Dispose();
                }
                else if (playerType == typeof(WaveOut))
                {
                    WaveOut player = (WaveOut)playerObj;
                    player.Pause();
                    player.Dispose();
                }

                musics.Remove(path);
                SyncListItems();
            }
        }
Exemplo n.º 4
0
        private void GlobalTimer_Tick(object sender, EventArgs e)
        {
            if (CheckStringItem(listBox1.SelectedItem, out string path))
            {
                if (musics.TryGetValue(path, out object playerObj))
                {
                    Type playerType = playerObj.GetType();

                    if (playerType == typeof(SoundPlayer))
                    {
                        SoundPlayer player = (SoundPlayer)playerObj;

                        //player.Stop();
                    }
                    else if (playerType == typeof(MciPlayer))
                    {
                        MciPlayer player = (MciPlayer)playerObj;
                        int       position = player.GetPosition(), length = player.GetLength();
                        positionLabel.Text = $"{player.GetPosition()} / {player.GetLength()}";
                        trackBar2.Maximum  = length;
                        trackBar2.Value    = position;
                    }
                    else if (playerType == typeof(WaveOut))
                    {
                        //WaveOut player = (WaveOut)playerObj;
                        //player.Stop();
                    }
                }
            }
        }
Exemplo n.º 5
0
        void GetMusicMode(string path)
        {
            if (musics.TryGetValue(path, out object playerObj))
            {
                Type playerType = playerObj.GetType();

                if (playerType == typeof(MciPlayer))
                {
                    MciPlayer player = (MciPlayer)playerObj;
                    MessageBox.Show(player.GetState().ToString());
                }
                else if (playerType == typeof(WaveOut))
                {
                    WaveOut player = (WaveOut)playerObj;
                    MessageBox.Show(player.PlaybackState.ToString());
                }
            }
        }
Exemplo n.º 6
0
        void PlayNewMusic(string path)
        {
            try
            {
                if (radioButton1.Checked)
                {
                    SoundPlayer player = new SoundPlayer();
                    player.SoundLocation = path;

                    musics[path] = player;
                }
                else if (radioButton2.Checked)
                {
                    MciPlayer player = new MciPlayer(path);
                    player.Open();

                    musics[path] = player;
                }
                else if (radioButton3.Checked)
                {
                    WaveOut         player     = new WaveOut();
                    AudioFileReader fileReader = new AudioFileReader(path);
                    player.Init(fileReader);

                    musics[path] = player;
                }
                else
                {
                    MessageBox.Show("No play type checked.", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "添加失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            SyncListItems();
            System.Media.SystemSounds.Beep.Play();
        }
Exemplo n.º 7
0
        void PlayMusicWait(string path)
        {
            if (musics.TryGetValue(path, out object playerObj))
            {
                Type playerType = playerObj.GetType();

                if (playerType == typeof(SoundPlayer))
                {
                    SoundPlayer player = (SoundPlayer)playerObj;
                    player.PlaySync();
                }
                else if (playerType == typeof(MciPlayer))
                {
                    MciPlayer player = (MciPlayer)playerObj;
                    player.PlayWait();
                }
                else if (playerType == typeof(WaveOut))
                {
                    //WaveOut player = (WaveOut)playerObj;
                }
            }
        }
Exemplo n.º 8
0
        void GetMusicLength(string path)
        {
            if (musics.TryGetValue(path, out object playerObj))
            {
                Type playerType = playerObj.GetType();

                if (playerType == typeof(SoundPlayer))
                {
                    SoundPlayer player = (SoundPlayer)playerObj;
                }
                else if (playerType == typeof(MciPlayer))
                {
                    MciPlayer player = (MciPlayer)playerObj;
                    MessageBox.Show(player.GetLength().ToString());
                }
                else if (playerType == typeof(WaveOut))
                {
                    WaveOut player = (WaveOut)playerObj;
                    //MessageBox.Show(player.Length);
                }
            }
        }
Exemplo n.º 9
0
        void PauseMusic(string path)
        {
            if (musics.TryGetValue(path, out object playerObj))
            {
                Type playerType = playerObj.GetType();

                if (playerType == typeof(SoundPlayer))
                {
                    SoundPlayer player = (SoundPlayer)playerObj;
                    player.Stop();
                }
                else if (playerType == typeof(MciPlayer))
                {
                    MciPlayer player = (MciPlayer)playerObj;
                    player.Pause();
                }
                else if (playerType == typeof(WaveOut))
                {
                    WaveOut player = (WaveOut)playerObj;
                    player.Pause();
                }
            }
        }
Exemplo n.º 10
0
        void GetMusicPosition(string path)
        {
            if (musics.TryGetValue(path, out object playerObj))
            {
                Type playerType = playerObj.GetType();

                if (playerType == typeof(SoundPlayer))
                {
                    //SoundPlayer player = (SoundPlayer)playerObj;
                    //player.Stop();
                }
                else if (playerType == typeof(MciPlayer))
                {
                    MciPlayer player = (MciPlayer)playerObj;
                    MessageBox.Show(player.GetPosition().ToString());
                }
                else if (playerType == typeof(WaveOut))
                {
                    //WaveOut player = (WaveOut)playerObj;
                    //player.Stop();
                }
            }
        }
Exemplo n.º 11
0
        void SeekMusic(string path, int position)
        {
            if (musics.TryGetValue(path, out object playerObj))
            {
                Type playerType = playerObj.GetType();

                if (playerType == typeof(SoundPlayer))
                {
                    //SoundPlayer player = (SoundPlayer)playerObj;
                    //player.Stop();
                }
                else if (playerType == typeof(MciPlayer))
                {
                    MciPlayer player = (MciPlayer)playerObj;
                    player.Seek(position);
                }
                else if (playerType == typeof(WaveOut))
                {
                    //WaveOut player = (WaveOut)playerObj;
                    //player.Stop();
                }
            }
        }
Exemplo n.º 12
0
        void SeekMusicToStart(string path)
        {
            if (musics.TryGetValue(path, out object playerObj))
            {
                Type playerType = playerObj.GetType();

                if (playerType == typeof(SoundPlayer))
                {
                    SoundPlayer player = (SoundPlayer)playerObj;
                    player.Stop();
                    player.Play();
                }
                else if (playerType == typeof(MciPlayer))
                {
                    MciPlayer player = (MciPlayer)playerObj;
                    player.SeekToStart();
                }
                else if (playerType == typeof(WaveOut))
                {
                    //WaveOut player = (WaveOut)playerObj;
                    //player.Stop();
                }
            }
        }