当前位置: 首页>>代码示例>>C#>>正文


C# SoundPlayer.PlaySync方法代码示例

本文整理汇总了C#中System.Media.SoundPlayer.PlaySync方法的典型用法代码示例。如果您正苦于以下问题:C# SoundPlayer.PlaySync方法的具体用法?C# SoundPlayer.PlaySync怎么用?C# SoundPlayer.PlaySync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Media.SoundPlayer的用法示例。


在下文中一共展示了SoundPlayer.PlaySync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

		public static void Main()
		{
			var Error1 = File.ReadAllBytes("MySounds.WaveComponent/Error1.wav");
			var Error1Player = new SoundPlayer(new MemoryStream(Error1));

			Error1Player.PlaySync();
			Error1Player.PlaySync();
			Error1Player.PlaySync();

			Console.WriteLine("other projects: ");
			Console.WriteLine("# http://naudio.codeplex.com/sourcecontrol/changeset/view/28884?projectName=naudio#");

			Console.WriteLine();

			var MyContent = new MyContent();


			MyContent.WriteTo((sender, args) => ShowProperties((MyContent.WriteToArguments)args));

			Console.WriteLine();
			// you really should not use headphones with PC speakers

			TestMemoryStream();


			Console.ForegroundColor = ConsoleColor.Yellow;

			Action<string> f = logo;

			f("hi");

			Console.WriteLine("got music?");



			var a = WaveExampleType.ExampleSquareWave.ToSoundPlayer(68);
			var b = WaveExampleType.ExampleSawtoothWave.ToSoundPlayer(115);
			var c = WaveExampleType.ExampleSquareWave.ToSoundPlayer(168);

			a.PlaySync();
			a.Stream.WriteTo("a.wav");


			b.PlaySync();
			c.PlaySync();

			//b.Stream.WriteTo("b.wav");
			//c.Stream.WriteTo("c.wav");

			//return 0;
		}
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:51,代码来源:Program.cs

示例2: Play

 public void Play(string src)
 {
     using(SoundPlayer sp = new SoundPlayer(src)) {
         sp.PlaySync ();
         sp.Dispose ();
     }
 }
开发者ID:niwakazoider,项目名称:unicast,代码行数:7,代码来源:Sound.cs

示例3: Main

        static void Main(string[] args)
        {
            int randomSeconds = 0;
            bool isTimeProvided = false;

            int flag = 0;

            //default values for time start and end
            const int DEFAULT_RANGE_START = 1800000;  //30 minutes
            const int DEFAULT_RANGE_END = 2400000;  //40 minutes

            //time range variables
            int customStart = DEFAULT_RANGE_START;
            int customEnd = DEFAULT_RANGE_END;

            while(flag == 0)
            {

                //play sound
                var Player = new System.Media.SoundPlayer();
                Player.SoundLocation = @"D:\Programs\knmp_win\meow.wav";
                Player.PlaySync();

                //waits a random time within the specified range
                System.Threading.Thread.Sleep(Utility.Random(customStart, customEnd));

                //using System.Linq;
                //using System.Threading.Tasks;
            }
        }
开发者ID:LukasMMarinovic,项目名称:knmp_win,代码行数:30,代码来源:Program.cs

示例4: Play

        // Conversion extracted from the sample voice_synthesis.cs (RSSDK\framework\CSharp\voice_synthesis.cs)
        // To understand a little bit more about the WAV file format, acess the following links: 
        //     - http://www-mmsp.ece.mcgill.ca/documents/AudioFormats/WAVE/WAVE.html
        //     - http://www.sonicspot.com/guide/wavefiles.html
        public static void Play(PXCMAudio.AudioData audioData, PXCMAudio.AudioInfo audioInfo) {
            using (var memoryStream = new MemoryStream()) {
                using (var bw = new BinaryWriter(memoryStream)) {
                    bw.Write(0x46464952);  // chunkIdRiff:'FFIR'
                    bw.Write(0);           // chunkDataSizeRiff
                    bw.Write(0x45564157);  // riffType:'EVAW'
                    bw.Write(0x20746d66);  // chunkIdFmt:' tmf'
                    bw.Write(0x12);        // chunkDataSizeFmt
                    bw.Write((short)1);         // compressionCode
                    bw.Write((short)audioInfo.nchannels);  // numberOfChannels
                    bw.Write(audioInfo.sampleRate);   // sampleRate
                    bw.Write(audioInfo.sampleRate * 2 * audioInfo.nchannels); // averageBytesPerSecond
                    bw.Write((short)(audioInfo.nchannels * 2));   // blockAlign
                    bw.Write((short)16);        // significantBitsPerSample
                    bw.Write((short)0);         // extraFormatSize
                    bw.Write(0x61746164);  // chunkIdData:'atad'
                    bw.Write(0);           // chunkIdSizeData

                    bw.Write(audioData.ToByteArray());
                    long pos = bw.Seek(0, SeekOrigin.Current);
                    bw.Seek(0x2a, SeekOrigin.Begin); // chunkDataSizeData
                    bw.Write((int)(pos - 46));
                    bw.Seek(0x04, SeekOrigin.Begin); // chunkDataSizeRiff
                    bw.Write((int)(pos - 8));
                    bw.Seek(0, SeekOrigin.Begin);

                    using (var soundPlayer = new SoundPlayer(memoryStream)) {
                        soundPlayer.PlaySync();
                    }
                }
            }
        }
开发者ID:mbahar94,项目名称:SharpSenses,代码行数:36,代码来源:RealSenseAudioPlayer.cs

示例5: Main

        static void Main(string[] args)
        {
            string soundFile = @"c:\Windows\Media\notify.wav";
            string message = "Time to make the donuts.";
            int minutes = 0;
            int count = 3;

            if (args.Length == 0)
                Console.WriteLine(usage);

            if (args.Length > 3 && File.Exists(args[3]))
                soundFile = args[3];

            if (args.Length > 2)
                Int32.TryParse(args[2], out count);

            if (args.Length > 1)
                message = args[1];

            if (args.Length > 0 && Int32.TryParse(args[0], out minutes))
                Thread.Sleep(minutes * 60 * 1000);

            ThreadPool.QueueUserWorkItem((state) =>
                {
                    using (SoundPlayer simpleSound = new SoundPlayer(soundFile))
                    {
                        for (int i = 0; i < count; i++)
                            simpleSound.PlaySync();
                    }

                });

            new Alert(message).ShowDialog();
        }
开发者ID:jeffesp,项目名称:Alarm,代码行数:34,代码来源:Program.cs

示例6: BeepBeep

        public static void BeepBeep(int Amplitude, int Frequency, int Duration)
        {
            double A = ((Amplitude * (System.Math.Pow(2, 15))) / 1000) - 1;
            double DeltaFT = 2 * Math.PI * Frequency / 44100.0;

            int Samples = 441 * Duration / 10;
            int Bytes = Samples * 4;
            int[] Hdr = { 0X46464952, 36 + Bytes, 0X45564157, 0X20746D66, 16, 0X20001, 44100, 176400, 0X100004, 0X61746164, Bytes };
            using (MemoryStream MS = new MemoryStream(44 + Bytes))
            {
                using (BinaryWriter BW = new BinaryWriter(MS))
                {
                    for (int I = 0; I < Hdr.Length; I++)
                    {
                        BW.Write(Hdr[I]);
                    }
                    for (int T = 0; T < Samples; T++)
                    {
                        short Sample = System.Convert.ToInt16(A * Math.Sin(DeltaFT * T));
                        BW.Write(Sample);
                        BW.Write(Sample);
                    }
                    BW.Flush();
                    MS.Seek(0, SeekOrigin.Begin);
                    using (SoundPlayer SP = new SoundPlayer(MS))
                    {
                        SP.PlaySync();
                    }
                }
            }
        }
开发者ID:vternal3,项目名称:ASCII-RPG,代码行数:31,代码来源:Beep.cs

示例7: Main

        static void Main(string[] args)
        {

            string[] soundUrls = new string[] {
                "http://www.wavsource.com/snds_2016-01-10_6357263721580594/movies/2001/disconnect_me.wav",
                "http://www.wavsource.com/snds_2016-01-10_6357263721580594/movies/star_trek/2needs_of_the_many.wav",
                "http://www.wavsource.com/snds_2016-01-10_6357263721580594/movies/terminator/t2_hasta_la_vista.wav"
            };

            Random rand = new Random();
            var sound = soundUrls[rand.Next(0, soundUrls.Length)];
            var playSound = new SoundPlayer(sound);


            try
            {
                playSound.PlaySync();
                Console.WriteLine();
                Console.ReadLine();
            }
            catch (WebException)
            {
                Console.WriteLine("Sorry, no available internet connection at this time");
                throw;
            }
            
        }
开发者ID:BritGirlCoder,项目名称:Console-Movie-Quotes,代码行数:27,代码来源:Program.cs

示例8: OpenPullRequestMonitor

        public OpenPullRequestMonitor(TimeSpan timespan, ItemState state=ItemState.Open)
        {
            var pollingPeriod = timespan.TotalMilliseconds;
            _timer = new Timer(pollingPeriod) {AutoReset = true};
            _timer.Elapsed += (sender, eventArgs) =>
            {
                var prs = 0;
                Task.Run(async () =>
                {
                    var requests = await PollGitHub(state);
                    prs = requests.Count;
                    _pr = requests.FirstOrDefault();
                    Console.WriteLine("Polled PR count:" + prs);
                }).Wait();

                if (prs > OpenPrs)
                {
                    var soundPlayer = new SoundPlayer("fanfare3.wav");
                    soundPlayer.PlaySync();
                    if (_pr != null)
                    {
                        var speech = new SpeechSynthesizer();
                        speech.Speak("New pull request.");
                        speech.Speak(_pr.Title);
                    }

                    OpenPrs = prs;
                }
                else if (prs < OpenPrs)
                {
                    OpenPrs = prs;
                }
            };
        }
开发者ID:awcoats,项目名称:PRNotifier,代码行数:34,代码来源:OpenPullRequestMonitor.cs

示例9: OnDraw

        private static void OnDraw(EventArgs args)
        {
            if (test > Game.Time) Drawing.DrawText(textx, texty, Color.Red, "MORE THAN ONE Enemy detected");
            if (dangers.pos.X == 0) return;
            if (dangers.time < Game.Time || (skip % 5 == 0 && dangers.pos.Distance(dangers.hero.Position) > range + 1000))
            {
                delay = 0;
                dangers.pos.X = 0;
            }
            string g = "";
            if (dangers.count) g = "MORE THAN ONE ";
            if ((int)(Game.Time * 2) % 2 == 1) Drawing.DrawText(textx, texty, Color.Red, g+"Enemy detected");
            Drawing.DrawCircle(dangers.pos, 1400, Color.Crimson);
            delay++;

                if (delay == 10 && sound.GetValue<Boolean>() && lastbeep < Game.Time)
                    ThreadPool.QueueUserWorkItem(ignoredState =>
                    {
                        lastbeep = Game.Time + lb.GetValue<Slider>().Value;
                        using (var player = new SoundPlayer(Resources.b))
                        {
                            player.PlaySync();
                        }
                    });
        }
开发者ID:werdbrian,项目名称:LeagueSharp-22,代码行数:25,代码来源:Program.cs

示例10: Play

 static void Play(string path)
 {
     using (var file = new FileStream(path, FileMode.Open, FileAccess.Read))
     {
         var player = new SoundPlayer(new OggDecodeStream(file));
         player.PlaySync();
     }
 }
开发者ID:hultqvist,项目名称:csvorbis,代码行数:8,代码来源:Program.cs

示例11: playsound

 /// <summary>
 /// Function in <see cref="GPIOPin"/> to play a sound.
 /// </summary>
 /// <param name="pin">The Pin of the Buzzer (GPIO PIN!)</param>
 /// <param name="duration">The time how long a single tone should last for.</param>
 /// <param name="repeats">The humber of repeats</param>
 public static void playsound(int repeats)
 {
     for(int i=0;i<repeats;i++)
     {
         SoundPlayer sp = new SoundPlayer(System.IO.Directory.GetCurrentDirectory() + "/beep.wav");
         sp.PlaySync();
     }
 }
开发者ID:DiplomarbeitFHCAMPUS02,项目名称:Zeiterfassungsterminal,代码行数:14,代码来源:GpioPin.cs

示例12: Main

 static void Main(string[] args)
 {
     using (var file = new FileStream(args[0], FileMode.Open, FileAccess.Read))
     {
         var player = new SoundPlayer(new OggDecodeStream(file));
         player.PlaySync();
     }
 }
开发者ID:skolima,项目名称:csvorbis,代码行数:8,代码来源:OggPlayer.cs

示例13: ProduceSound

 public void ProduceSound()
 {
     using (SoundPlayer s = new SoundPlayer())
     {
         s.SoundLocation = "Sounds/dog_bark_x.wav";
         s.PlaySync();
     }
 }
开发者ID:EBojilova,项目名称:SoftUni-3,代码行数:8,代码来源:Dog.cs

示例14: Main

 static void Main(string[] args)
 {
     using (var file = new FileStream("audio.wav",
         FileMode.Open, FileAccess.Read, FileShare.Read))
     {
         var player = new SoundPlayer(file);
         player.PlaySync();
     }
 }
开发者ID:AmoebaThree,项目名称:Playground,代码行数:9,代码来源:Program.cs

示例15: timer1_Tick

 private void timer1_Tick(object sender, EventArgs e)
 {
     SoundPlayer sp = new SoundPlayer("Resources\\s.wav");
     lblPlayer.Text = "";
     lbl1.Text = "Время вышло!!!";
     sp.PlaySync();
     btnYes.DialogResult = DialogResult.No;
     timer1.Stop();
 }
开发者ID:Ihor01,项目名称:GuessMelody,代码行数:9,代码来源:fDialog.cs


注:本文中的System.Media.SoundPlayer.PlaySync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。