I am working on a console application where i have to deal with multiple sound file with all of same type(.wav or .mp3). I have the option to chose between the two.
I can play the sound fine using PlaySound() function but i need some extra features.
I need pausing the sound and then play from the position where it paused last time.
OR
Set a time from where playing should start and time for which it should play.
1 of the two options will do the job.
I am working on windows with DEV C++ compiler.
Any help and ideas?
Use the Windows Media Player activeX control for anything more sophistcated than straight playing of a WAV file. It is far easier.
See "Using the Windows Media Player Control in a C++ Program" on MSDN:
http://msdn.microsoft.com/en-us/library/windows/desktop/dd564580(v=vs.85).aspx
Related
I'm a beginner when it comes to programming and I wanted to do a personal project in C++ to develop my skills. The project I had in mind involves playing audio on my laptop (running Windows 10), analyzing it, and sending data to an arduino that will change the color and brightness of LED lights in sync with the audio that's playing. I would like it so that I can simply, for example, just play a song on Spotify or a music video on Youtube etc. and the program will get data from that audio stream as an input. Elsewhere I've seen programs use audio from recorded WAV files or streams from a microphone as input, but not what I have in mind. I want to use this program for parties, so using a microphone as a workaround wouldn't be ideal.
Is this even possible? And if so how should I approach this problem? Are there certain APIs I should look to or what? If the program gets audio as the input, would I still be able to play music on something like a bluetooth speaker as well? Or can it only send data to one place at a time?
My roommate who is much better at programming than me accomplished this on Mac using Swift, and while I don't have a Mac, would using Linux instead make this easier?
Modern windows has “Stereo Mix” recording device, just for that. Here’s how to enable: https://technicalustad.com/enable-stereo-mix-in-windows-10/
After that setup, in your C++ program use any recording API you want.
Here’s a sample that does what you ask for, opens a recording device, starts recording, and sends audio samples to the class provided in the argument: https://learn.microsoft.com/en-us/windows/win32/coreaudio/capturing-a-stream You probably want to trade CPU time for latency for your application, i.e. don’t Sleep for hnsActualDuration/REFTIMES_PER_MILLISEC/2, change into Sleep( 0 ) or Sleep( 1 )
I just need a simple program which allows me to play and stop an audio file. I'm guessing OpenAL is the way to go? All I need is this functionality - start audio file with spacebar and stop audio file with a second press of the spacebar. I notice the OpenAL documentation is quite involved. Can someone point me to something really simple in order to just get the start/stop functionality of a .wav file?
OpenAL may not be the simplest choice. If you use a gui-framework like QT, check for what their ecosystems provide for playing sound (e.g. qsound). Another choice may be Allegro which may feel more straightforward.
For OpenAL, there is a working example to play a wav in the example repositories. Playback can be paused using alSourcePause.
Edit:
For choosing libraries I like to consult Awesome-cpp. The simple_playback.c example of mini_al looks extremely straightforward. Simply use mal_device_stop(&device) to pause the running playback and mal_device_start(&device) to continue. Works perfectly on my machine and seems very portable.
For a semester project, I am planning to make a media player in visual studio c++ console application which will provide the functions of play, pause, previous, next, shuffle, repeat, different playlists of recently played, most played songs, search a song etc.
However, I can't find a way to do that without using multi-threading (which I dont know at the moment). To avoid multi-threading, I was thinking of making use of windows media player .dll if that is possible. I am expecting to give a path to play function which plays the song in background and then changes the song when I give it another path using the 'Next Song' function. Kindly tell how to do that if this is possible. Thank you.
For your console application. You can simply call the system to launch windows media player
system ("start wmplayer.exe -p C:\\Folder\\Music\\Sample.mp3");
this will start your player. You can change track by doing this
system ("start wmplayer.exe -p C:\\Folder\\Music\\Sample2.mp3");
this will run Sample2.mp3. You can store other information in your program like for playlist store information in an array of string and start them individually.
Moreover if you want to don't want to see the WM Player interference you can use some sort of script like https://gallery.technet.microsoft.com/scriptcenter/2c3caa06-ca29-4faa-a16d-7db57e80428b
I think this is the simplest solution of your problem.
I've been working on a C++ application that plays a different video depending on what a user did. So Far I've worked with OpenCV to only play the video, since I need to do some changes on the video on real time. Since OpenCV doesn't play sound, I need to use a different library to play the sound independently. So far I tried FFMPEG, but I couldn't get it work, since I'm not experienced on working on C++ (At least in a computer with external libraries, I normally programm it on microcontrollers).
The sound doesn't need to sync with the video and it also only should run on Windows. What is my best option?
Thanks.
If it does only need to work for Windows, the WINAPI function PlaySound should fulfil your requirements.
#include "windows.h"
#include "mmsystem.h"
void play()
{
PlaySound(TEXT("sound.wav"), NULL, SND_FILENAME); // plays sound.wav once
}
To make this work you need to link against winmm.lib.
If your file name is not ASCII you should use PlaySoundA (ANSI) or PlaySoundW (unicode) instead.
See also this question if the sound is not played properly.
I am making a program in C++ for Windows XP that requires sound to be played so that any program that is currently recording the microphone can hear it, but it will not come out of the speakers. There seems to be no "real" way of doing it, but it is possible to go into "sndvol32 -R" and set the Wave out mix or similar as the current input device. Then you can turn the master volume to 0, play the sound, turn it back up, and reset the input device to the microphone. Is there a way of doing this transparently, or setting the current input device using functions, so that you dont have to see sndvol32 pop up?
Thanks
Doing this would require a complicated kernel-level driver.
Fortunately for you, someone has already done this (it's not free, but it's a fantastic program).