Kinect Hovering event handler - c#

I am creating a WPF application using Kinect SDK 1.8
I want to press a button with hand.
private void playTeeth1Sound(object sender,RoutedEventArgs e)
{
System.Media.SoundPlayer teeth1_Sound = new System.Media.SoundPlayer(#"../../soundForKinect/1.wav");
teeth1_Sound.Play();
}

I don't see any Kinect specific code in your question, and I'm not sure what the questions is, but one thing to consider in the code snippet in your question is:
Every time this method is called (presumably when the button is pressed), it has to:
instantiate a new System.Media.SoundPlayer
load the sound file into teeth1_Sound
play the sound file with the Play() method
You might find there is a delay each time as the code re-instantiates teeth1_Sound and reloads the sound file? It might be easier to load all the sound files when the app is starting up, have them ready to Play() as soon as you need them?

Related

Windows media player play states in C#

I´m beginner in C# coding. Especially, when it comes to use Wmp in C#. I work in visual studio 2017, on a project called "station information system" for a small, private railway in our country. The whole functionality of program I´ve done correctly, it works, so now I need to come up with an idea, how to make it playing. My program exports exact names of mp3 files into a hidden listbox. To generate patches I use this code:
axWindowsMediaPlayer1.URL = Path.Combine(Environment.CurrentDirectory, #"ZVUK\", listBox2.SelectedItem.ToString());
It works, so I came to the other functionality I need from Wmp. When Wmp plays the full song, I need it to change the index in listbox and go to second song, then third and so on. I used this condition:
if (axWindowsMediaPlayer1.playState() = WMPLib.WMPPlayState.wmppsMediaEnded)
The part "playState()" is underlined and it shows me an error: "Non-invocable member "axWindowsMediaPlayer1.playState" cannot be used like a method." I tried deleting brackets but it just underlined the whole part "axWindowsMediaPlayer1.playState". Can someone help me?
Thank you very much.
You can use the following code to play the file one by one.
private void button1_Click(object sender, EventArgs e)
{
SoundPlayer player = new SoundPlayer(#"2.wav");
player.PlaySync();
player = new SoundPlayer(#"\1.wav");
player.PlaySync();
}

Using the VLC ActiveX plugin to watch youtube videos C#

Recently I have started messing around with the VLC ActiveX plugin trying to play youtube videos in a WindowsFormApplication and I have run into some issues that I couldn't find any mention of or solution to. For simplicity I made a new project to demonstrate my problems:
private void button1_Click(object sender, EventArgs e)
{
Player.playlist.play();
}
private void button2_Click(object sender, EventArgs e)
{
url = textBox1.Text;
Player.playlist.add(url);
listBox1.Items.Add(url);
}
2 buttons, play and add to playlist.
Problem 1:
Audio cuts out a few seconds before the end of the video.
Problem 2:
I have been unable to get the control to play the next video in the playlist. It just reaches the end of the first video. If I click the play button again, it plays the first video. One thing I thought might be causing it was the AutoPlay property but it's set to true.
Problem 3:
The Player.playlist.next function, like most thing doesn't have a description and does not let me go to the next video in the playlist.
Problem 4:
The AutoLoop property does not work, assuming that it's supposed to get the control to loop a video.
Problems number 2 and 3 make me think that the songs aren't being added to the playlist correctly, but again I was unable to find any way to confirm or solve that issue.
Using VisualStudio 2015, VLC plugin version, as stated in the control properties, 3.0.1 Vetinari.
(edit) after testing I know that the videos are added to the playlist, but still it won't autoplay the next in playlist at the end.

Reliable way to capture gamepad button press (non-game application)

I am trying to use a gamepad to control an application. It's not a game, just a plain application using Windows Forms. So it doesn't have a game loop/update process or anything like that. I wouldn't like to use XNA because I think it's a huge overload just to capture a button press.
I am experimenting with both SlimDX and SharpDX. As I understand, they are just wrappers for DirectX, right?
Looking at the documentation, it seems like there is no event for a button press. So I have been looking for an alternative. I have tried adding a timer (from the System.Windows.Forms.Timer class), and reading the state of the gamepad like this:
private void timer_tick(object sender, EventArgs e)
{
State s = controller.GetState();
stateLabel.Text = s.Gamepad.Buttons == GamepadButtonFlags.A ? "A" : "";
}
With a small enough interval between timer ticks (I'm using 10ms), I can see whether the button is pressed or not. However, I don't want to handle the button press multiple times should the button be held down - I need to make sure it has been released before handling the button press again. Between two ticks of the timer, I don't know if a button was pressed twice or if it was just being held down.
I thought about using the packet number in the controller state, but it will change at the slightest touch on an analog stick or shoulder trigger.
Help?
From what I can gather after reading you question over a few times is that you are wanting to log a button press only 1 time until it is released. You probably should use the packet number technique to keep track of any changes to the other input.
To get a single input from the button being held down as opposed to getting continuous input (1 as opposed to 11111111...etc) create an old state an a current state. Then compare the old state with the new state.
Something like this:
class Input
{
State old;
void GetInput()
{
State new = controller.GetState();
if (this.old.GamePad.Buttons == GamepadButtonFlags.A && new.GamePad.Buttons == GamepadButtonFlags.A)
{
// Do stuff that will be called only once.
}
this.old = new;
}
}

Is there a pixel search function in C#?

I currently have made a program in AutoIT that has PixelSearch methods inside of it. Anyway, I have a pretty intense GUI that can be annoying to fill out everytime you run it, so I decided I would make a save/load settings button. It turns out that AutoIT handles file reading/writing pretty inefficiently, so writing to the file to "save" settings and reading from the file to "load" settings was out of the question. I decided to make something in C# since the FileStream class is amazing. But, to replace the AutoIT program, I need the function pixelsearch, which basically searches for a certain pixel in a rectangle/point defined. Anyone have an idea how this is created, or if there is one already how it is used?
P.S: Is there also a way that I can save the cursor's location after the user presses a certain button in C#? I was thinking of a mouseEvent of some sort.
you certainly can save the mouse click locations, try to use the mouse events mouseUp(object sender, MouseEventArgs e) mouseDown(object sender, MouseEventArgs e) ... inside the function you can open a stream and write the location everytime then close it , the location is e.Location

How to play a sound in C#, .NET

I have a Windows application written in C#/.NET.
How can I play a specific sound when a button is clicked?
You could use:
System.Media.SoundPlayer player = new System.Media.SoundPlayer(#"c:\mywavfile.wav");
player.Play();
You can use SystemSound, for example, System.Media.SystemSounds.Asterisk.Play();.
For Windows Forms one way is to use the SoundPlayer
private void Button_Click(object sender, EventArgs e)
{
using (var soundPlayer = new SoundPlayer(#"c:\Windows\Media\chimes.wav")) {
soundPlayer.Play(); // can also use soundPlayer.PlaySync()
}
}
MSDN page
This will also work with WPF, but you have other options like using MediaPlayer MSDN page
Additional Information.
This is a bit high-level answer for applications which want to seamlessly fit into the Windows environment. Technical details of playing particular sound were provided in other answers. Besides that, always note these two points:
Use five standard system sounds in typical scenarios, i.e.
Asterisk - play when you want to highlight current event
Question - play with questions (system message box window plays this one)
Exclamation - play with excalamation icon (system message box window plays this one)
Beep (default system sound)
Critical stop ("Hand") - play with error (system message box window plays this one)
 
Methods of class System.Media.SystemSounds will play them for you.
 
Implement any other sounds as customizable by your users in Sound control panel
This way users can easily change or remove sounds from your application and you do not need to write any user interface for this – it is already there
Each user profile can override these sounds in own way
How-to:
Create sound profile of your application in the Windows Registry (Hint: no need of programming, just add the keys into installer of your application.)
In your application, read sound file path or DLL resource from your registry keys and play it. (How to play sounds you can see in other answers.)
Code bellow allows to play mp3-files and in-memory wave-files too
player.FileName = "123.mp3";
player.Play();
from http://alvas.net/alvas.audio,samples.aspx#sample6 or
Player pl = new Player();
byte[] arr = File.ReadAllBytes(#"in.wav");
pl.Play(arr);
from http://alvas.net/alvas.audio,samples.aspx#sample7
To play an Audio file in the Windows form using C# let's check simple example as follows :
1.Go Visual Studio(VS-2008/2010/2012) --> File Menu --> click New Project.
2.In the New Project --> click Windows Forms Application --> Give Name and then click OK.
A new "Windows Forms" project will opens.
3.Drag-and-Drop a Button control from the Toolbox to the Windows Form.
4.Double-click the button to create automatically the default Click event handler, and add the following code.
This code displays the File Open dialog box and passes the results to a method named "playSound" that you will create in the next step.
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "Audio Files (.wav)|*.wav";
if(dialog.ShowDialog() == DialogResult.OK)
{
string path = dialog.FileName;
playSound(path);
}
5.Add the following method code under the button1_Click event hander.
private void playSound(string path)
{
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = path;
player.Load();
player.Play();
}
6.Now let's run the application just by Pressing the F5 to run the code.
7.Click the button and select an audio file. After the file loads, the sound will play.
I hope this is useful example to beginners...
I think you must firstly add a .wav file to Resources. For example you have sound file named Sound.wav. After you added the Sound.wav file to Resources, you can use this code:
System.Media.SoundPlayer player = new System.Media.SoundPlayer(Properties.Resources.Sound);
player.Play();
This is another way to play sound.

Categories

Resources