I prefer to use wavesurfer.js player in my web browser controller in C#.
The problem is wavesurfer isn't loading file.
Sample player is http://mypublic.kissr.com/
I am on windows forms applicaton. I tried with default webbrowser controller it didn't work.
then I tried with CefSharp browser controller. It still didn't work.
Any help is greatly appreciated.
Data View Waves Timer and Pointer location all these are important to me. that's why I need to use wavesurfer.
The link below, gives a very good tutorial, about playing mp3 files from a windows form with c#:
http://www.daniweb.com/software-development/csharp/threads/292695/playing-mp3-in-c
This link will lead you to a topic, which contains a lot information about how to play an mp3 song, using Windows forms. It also contains a lot of other projects, trying to achieve the same thing:
http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/3dbfb9a3-4e14-41d1-afbb-1790420706fe
For example use this code for .mp3:
WMPLib.WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer();
wplayer.URL = "My MP3 file.mp3";
wplayer.Controls.Play();
Then only put the wplayer.Controls.Play(); in the Button_Click event.
For example use this code for .wav:
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = "Sound.wav";
player.Play();
Put the player.Play(); in the Button_Click event, and it will work.
Related
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();
}
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?
In my application, I use UI MediaElement. But when i click the Windows key, the music stops.
I tried using:
MediaControl.PlayPressed += MediaControl_PlayPressed;
MediaControl.PausePressed += MediaControl_PausePressed;
MediaControl.PlayPauseTogglePressed += MediaControl_PlayPauseTogglePressed;
MediaControl.StopPressed += MediaControl_StopPressed;
I set source MediaElement:
media.Source = new Uri("http://stream-hq.mp3.zdn.vn/fsgggsfdlwjglwjAAAAA/2a3f830202ea6d29bc7c5a5146401566/4ff5620a/2011/12/27/a/4/a4fcc199a184a93cfeb0fe35642c53bf.mp3", UriKind.RelativeOrAbsolute);
Please help me!
For a Metro/WinRT app to play audio in background, the app needs the following:
A MediaElement control that:
Is in a XAML page.
The AudioCategory property set to BackgroundCapableMedia (as in Armando's answer). There are other values for games or communication systems as needed. See the Audio Playback in a Metro Application for information on what the different options mean.
Use the MediaControl object to capture at least the following. Other events and properties can be handled if desired but the following are required for background playback to function.
PlayPressed
StopPressed
PlayPauseTogglePressed
PausePressed
Add audio to the list of support background tasks in the applications manifest. The manifest is usually called Package.appxmanifest. Select it in the Solution Explorer, go to the Declarations tab and check "Audio" as shown:
See the Transport Controls Guide for more info about capturing hardware buttons (e.g. play/pause on the keyboard) and the quickstart guide for creating a media player for more info.
This would be my first answer. Make sure you set AudioCategory="BackgroundCapableMedia" in your XAML like this:
<MediaElement x:Name="backgroundMusic"
AutoPlay="True"
AudioCategory="BackgroundCapableMedia"
Source="mms://betafm.santafe-conicet.gov.ar:1175">
</MediaElement>
Hope it helps!
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.
MediaElement doesnt work for me in my WPF application.
mediaElement1.LoadedBehavior = MediaState.Manual;
mediaElement1.Source = new Uri(#"C:\Music\MySong.mp3", UriKind.RelativeOrAbsolute);
mediaElement1.Play();
When I do this in my Window1.xaml.cs file. Nothing happens. Atleast I cant hear anything. I have tried all kind of different things, but no sound.
In winforms:
axWindowsMediaPlayer1.URL = #"C:\Music\MySong.mp3";
axWindowsMediaPlayer1.Ctlcontrols.play();
Works without any problems. Any simple solution or things to try?
Ok I solved it. WPF only support MediaElement if you have Windows Media Player 10 or above. I was running WMP9.
Though I'm also new in wpf,One thing you should notice about media element is that providing source in the XAML tag is not worth working.
you need to provide the source with the urikind like this
media.Source = new Uri(#"E:\Pehli_Baar_Mohabbat.mp3",UriKind.RelativeOrAbsolute);
put this line in window constructor
and set loadedbehavious=manual and then check.
mediaElement1.LoadedBehavior = MediaState.Manual;
---- edit to-----
mediaElement1.LoadedBehavior = System.Windows.Controls.MediaState.Manual;