soundplayer

I can't find the System.Media namespace in Visual Studio 2019

大兔子大兔子 提交于 2020-01-05 06:31:24
问题 Edit - ANSWER: I found the solution thanks to @LexLi and @Amy; I accidentally created a .NET Core console application instead of .NET Framework. Once I remade it as a .NET Framework app it had "System.Media" available. I'm relatively new (only a few weeks in) to learning C#, but I'm trying to make a console application text game, and I have a typewriter method I'm using to print messages to the display. public static void typewriter(string s) { // This method types strings out slowly. for

playback audio file from byte code (audio file format is CCITT A-Law)

送分小仙女□ 提交于 2020-01-04 13:40:05
问题 I want to playback audio file from byte code. I already have byte code for audio file. But when I playback with System.Media.SoundPlayer, I got error as "{Sound API only supports playing PCM wave files."}. My audio file format is (CCITT A-Law). Can any one who have this knowledge share with me pls?? Thanks. 回答1: The standard G.711 tells you how to convert 8 bit A-law into 16 PCM. Here's a code snippet 回答2: WAV files can be encoded in many ways, usually PCM or MP3. .NET only supports PCM. Use

How to run a .wav in client. ASP.NET

99封情书 提交于 2019-12-25 07:36:11
问题 I have an application that plays a wave file using the SoundPlayer class. However, when I publish the application in IIS, the file will not play. To use the SoundPlayer class I added a reference windows.dll, it may interfere? public void PlaySound() { try { while (1 == 1) { List<string> distinctMusic = GetMusicFile.Distinct().ToList(); for (int i = 0; i < distinctMusic.Count; i++) { player.SoundLocation = distinctMusic[i]; player.Play(); Thread.Sleep(GetMusicDuration[i] * 1000); player.Stop()

Play sound in both speaker and headset wpf

大兔子大兔子 提交于 2019-12-25 02:46:25
问题 I have an wpf application and i am using the soundPlayer class to play sound (for eg ringtone). Currently the tone plays either on speakers or on the headset (if its plugged in). I would like the application to play the tone on speaker even when the headsets are plugged in. I know there are ways to do this in android, but couldn't find any in wpf. Any help is appreciated. Thanks ! Sharing sample code : public void detectDevices() { int waveOutDevices = WaveOut.DeviceCount; switch

Stopping a SoundPlayer loop at the local level

拜拜、爱过 提交于 2019-12-25 01:26:09
问题 I'm working on setting up an alarm that pops up as a dialog with multiple sound file options the user can choose from. The problem I'm having is creating a sound player at the local level that I can close with a button. The problem I'm having is that the sound keeps looping when I close the form because the SoundPlayer doesn't exist within the button click event. here's what I have: void callsound() { if (SoundToggle == 0) // if sound enabled { if ((SoundFile == 0) && (File.Exists(@"attention

Do something after a music ends with SoundPlayer

て烟熏妆下的殇ゞ 提交于 2019-12-24 16:28:33
问题 I need to do something after my Async Loaded music file finishes. Let's say I want the program to exit or something. Now how do I make it do is after the music finishes? private void button1_Click(object sender, EventArgs e) { player.SoundLocation = @"Music\" + FileList[0]; player.LoadAsync(); } private void Player_LoadCompleted(object sender, AsyncCompletedEventArgs e) { if (player.IsLoadCompleted) { player.PlaySync(); } } 回答1: Since the PlaySync method is synchronous then it will not return

C# - Get time from soundplayer

元气小坏坏 提交于 2019-12-20 07:41:11
问题 Is there any way to get the number of milliseconds that have passed since the soundplayer started playing? So far I'm using Environment 's tick counter by getting the start time and then the current time every frame, but sometimes that's inaccurate and sometimes it's really off. At the beginning of the code I used startTime = Environment.TickCount; and then every frame i used long elapsed = Environment.TickCount - startTime; Is there an easier way to do this like HTML5 audio's player

Playing sounds on Console - C#

别等时光非礼了梦想. 提交于 2019-12-19 04:09:47
问题 I'm writing a Console application on C# and I want to play a sound when I display texts continuously. This is what I've done : static SoundPlayer typewriter = new SoundPlayer("typewriter"); static public void print(string str, int delay) { Thread skipThread = new Thread(skipText); typewriter.PlayLooping(); textgap = delay; foreach (char c in str) { Console.Write(c); if (textgap != 0) Thread.Sleep(textgap); } typewriter.Stop(); } typewriter.wav is imported to my project next to the .cs files

Play wav/mp3 from memory

徘徊边缘 提交于 2019-12-18 04:42:22
问题 I play mp3/wav from file to create a push effect. However on an Atom CPU based tablet PC, there is a delay when I touch the button. I'll try to play wav/mp3 from memory instead of file system. Can anyone give a code snippet or a clue? System.Media.SoundPlayer player = new System.Media.SoundPlayer(); player.SoundLocation = System.Windows.Forms.Application.StartupPath + "\\beep-7.wav"; player.Play(); 回答1: Something like this? public class MediaPlayer { System.Media.SoundPlayer soundPlayer;

How to append .wav format sounds to each other

一世执手 提交于 2019-12-12 15:42:33
问题 I am studying C# by myself by reading some books and watching some tutorials. So, i decided to make a small project at the same time, to get more experience and harden my knowledge. I am trying to create a text to speech program in Georgian(my language). I have done the same program in java but want to transfer it in C#, but i couldn't understand how to append different sounds to each other.For example, when my program wants to say a word "general" it divides the word in parts like this "ge"