Play two sounds simultaneusly
Reference PresentationCore
and WindowsBase
and try this...
var p1 = new System.Windows.Media.MediaPlayer();
p1.Open(new System.Uri(@"C:\windows\media\tada.wav"));
p1.Play();
// this sleep is here just so you can distinguish the two sounds playing simultaneously
System.Threading.Thread.Sleep(500);
var p2 = new System.Windows.Media.MediaPlayer();
p2.Open(new System.Uri(@"C:\windows\media\tada.wav"));
p2.Play();
EDIT
I received a downvote probably because at first glance this looks like it will play the second sound after the first is finished. It doesn't, they are played by windows asynchronously. The sleep is there so if you test this code verbatim you can hear the sounds play together, it wouldn't be noticeable without the delay since they are the same sound.
This code demonstrates the two sounds playing on separate threads on top of each other, which is sort of pointless since the playback doesn't block anyway
new System.Threading.Thread(() => {
var c = new System.Windows.Media.MediaPlayer();
c.Open(new System.Uri(@"C:\windows\media\tada.wav"));
c.Play();
}).Start();
System.Threading.Thread.Sleep(500);
new System.Threading.Thread(() => {
var c = new System.Windows.Media.MediaPlayer();
c.Open(new System.Uri(@"C:\windows\media\tada.wav"));
c.Play();
}).Start();
http://msdn.microsoft.com/en-us/library/system.windows.media.mediaplayer.stop.aspx
The class also has the control you need to stop playback
play multiple sounds simultaneously in javascript
You can use the Audio constructor
const music = new Audio('myPathTo/music.mp3')
const soundEffects = new Audio('myPathTo/effects.mp3')
and then
music.play()
soundEffects.play()
Play 2 sounds simultaneously with multiprocessing in python
If you want to have any control over the relative timing of the two sounds (for example, they should start simultaneously), using multiple processes is probably not a good solution. You should be mixing the signals within your application and writing out a single audio stream.
Since you are using audiolab, you already have the data in numpy arrays. This gives you all the flexibility you need to mix audio:
frames1, fs1, encoder1 = audiolab.wavread('audio1.wav')
frames2, fs2, encoder2 = audiolab.wavread('audio2.wav')
mixed = frames1 + frames2
audiolab.play(mixed, fs=44100)
If this causes the audio signal to clip (you hear clicks / pops), you may need to pre-scale the data before mixing:
mixed = frames1 / 2 + frames2 / 2
.. and if the sounds do not have equal length, it may take a little more work:
mixed = np.zeros(max(len(frames1), len(frames2)), dtype=frames1.dtype)
mixed[:len(frames1)] += frames1 / 2
mixed[:len(frames2)] += frames2 / 2
How to play two sounds simultaneously using Media Foundation
Could you elaborate a bit more ?
For example, you can restart a IMFMediaSource to reapeat it :
IMFMediaSource::Start :
Starts, seeks, or restarts the media source by specifying where to start playback.
Or you can simply stop the source and then start again :
IMFMediaSource::Stop
When a media source is stopped, its current position reverts to zero. After that, if the Start method is called with VT_EMPTY for the starting position, playback starts from the beginning of the presentation.
PS : I agree with Mgetz, if you only play simple wav files, XAudio2 is an option. Tell us your audio file format.
Play multiple sound at the same time
With JavaScript and the HTML5 Audio API you could do something like this:
var snd1 = new Audio();
var src1 = document.createElement("source");
src1.type = "audio/mpeg";
src1.src = "audio/Dombra.mp3";
snd1.appendChild(src1);
var snd2 = new Audio();
var src2 = document.createElement("source");
src2.type = "audio/mpeg";
src2.src = "audio/(TESBIHAT).mp3";
snd2.appendChild(src2);
snd1.play(); snd2.play(); // Now both will play at the same time
I have tested this in Chrome v. 20, and it seems to work :)
The <source>
tag is used to specify different formats of the same file - such that the browser can choose another format as fallback in case the first one is not supported. That is why your own suggested solution does not work.
Related Topics
The Name "Xyz" Does Not Exist in the Namespace "Clr-Namespace:Abc"
If Int32 Is Just an Alias for Int, How Can the Int32 Class Use an Int
Create PDF in Memory Instead of Physical File
How Does Comparison Operator Works with Null Int
Save Settings in a .Net Winforms Application
Why Won't Control Update/Refresh Mid-Process
405 Method Not Allowed Web API
Regex: C# Extract Text Within Double Quotes
Enumerate Windows Like Alt-Tab Does
Anonymous Types - Are There Any Distingushing Characteristics
Overriding Savechanges and Setting Modifieddate, But How to Set Modifiedby
Characters in String Changed After Downloading HTML from the Internet
How to Do .Net Binary Serialization of an Object When You Don't Have the Source Code of the Class
How to Use Webbrowser Control Documentcompleted Event in C#
How to Share Data Between Forms
How to Use Switch-Case on a Type
How to Check If Variable's Type Matches Type Stored in a Variable