Playing Audio in .Net / C#

前端 未结 5 412
天命终不由人
天命终不由人 2021-02-03 11:56

I\'m an experienced MFC programmer of many years, who for the more recent years has been developing commercial apps in Objective C for Mac and iOS - I\'m trying to get up to spe

5条回答
  •  孤城傲影
    2021-02-03 12:31

    Alvas.Audio has 3 audio players: Player

            player.FileName = "123.mp3";
            player.Play();
    

    PlayerEx

            public static void TestPlayerEx()
            {
                PlayerEx plex = new PlayerEx();
                plex.Done += new PlayerEx.DoneEventHandler(plex_Done);
                Mp3Reader mr = new Mp3Reader(File.OpenRead("in.mp3"));
                IntPtr format = mr.ReadFormat();
                byte[] data = mr.ReadData();
                mr.Close();
                plex.OpenPlayer(format);
                plex.AddData(data);
                plex.StartPlay();
            }
    
            static void plex_Done(object sender, DoneEventArgs e)
            {
                if (e.IsEndPlaying)
                {
                    ((PlayerEx)sender).ClosePlayer();
                }
            }
    

    and RecordPlayer

            public static void TestRecordPlayer()
            {
                RecordPlayer rp = new RecordPlayer();
                rp.PropertyChanged += new PropertyChangedEventHandler(rp_PropertyChanged);
                rp.Open(new Mp3Reader(File.OpenRead("in.mp3")));
                rp.Play();
            }
    
            static void rp_PropertyChanged(object sender, PropertyChangedEventArgs e)
            {
                switch (e.PropertyName)
                {
                    case RecordPlayer.StateProperty:
                        RecordPlayer rp = ((RecordPlayer)sender);
                        if (rp.State == DeviceState.Stopped)
                        {
                            rp.Close();
                        }
                        break;
                }
            }
    

提交回复
热议问题