Audio player component

Hello Juce friends…

I hope some one has surely developed sample audio player that play normal music files like wav/mid/mp3 …?
If so can any one please put source of that ?

THanks friends…

Hi acn, the dRowAudio AudioFilePlayer does that. It’s basically a wrapper around all the audio sources required to load and playback audio from a file, stream or memory block. Just create one, call setFile or similar and then start(). Links are in my sig.

If you need a UI, you can just hook up a button to play/pause it or use a PositionableAudioThumbnail for a wave display. Check the demo for their use.

Hope that’s what you’re looking for.

Hey Dave thanks.

It seems really good work you have already done.
Just a small que, is it free to use ? What ever here provided is so much for me,
I needed very basic things but this will certainly do all the work.

I have also seen basic work around audio files like midi and mp3 that is work by TheVinn.
That is also useful to me may be. thanks to vinny & swingcoder also.

can you please put some light, how can i simply play mp3 file ? what i am asking dave is which part of your code can help figuring that out ? Again thanks for your reply.

Well JUCE can play mp3 files, the actual stream decoding is done by either CoreAudioFormat, WindowMediaFormat or MP3AudioFormat depending on your platform and config flags. There are then a number of classes involved in actually reading the samples and passing them up to the audio hardware device. The AudioFilePlayer encapsulates most of the low-level classes so it can just be controlled like a player object i.e. with setFile, start, stop and pause methods.

There are 3 classes you would need to get this to work:
juce::AudioDeviceManager - to interface with the hardware device
juce::AudioSourcePlayer - pulls samples from a source to an AudioDeviceManager
drow::AudioFilePlayer - handles all the file reading, positioning etc.

In your header:

AudioDeviceManager audioDeviceManager; AudioSourcePlayer audioSourcePlayer; AudioFilePlayer audioFilePlayer;

In your implementation:

[code] audioDeviceManager.initialise (0, 2, nullptr, true);
audioDeviceManager.addAudioCallback (&audioSourcePlayer);
audioSourcePlayer.setSource (&audioFilePlayer);

audioFilePlayer.setFile ("<some path to file>");

I haven’t done a any MIDI file reading but that is really a different problem. dRowAudio is free to use under the GPLv2, comercial licences are available.

Hamm. that is good to know.
So AudioDeviceManager, AudioSourcePlayer - from Juce library
and AudioFilePlayer from drowAudio. sounds easy as you explained well.
(I think you mentioned drow:: just to distinguish or there is namespace “drow” available actually ?)
Can you please tell ? how can one generates build files for dRowAudio ? because from the downloaded part of repository i see no build files for either visual studio or . . or it can be directly included as a whole module same as you added in your demo application code ?

Yes the namespace thing is right, all my classes are in the drow namespace.

dRowAudio is a JUCE module. Just download the repository, drop the actual module folder “dRowAudio” (which contains the juce_module_info file) into your juce/modules folder and then run the Introjucer. It should appear alongside all the other JUCE modules. See Integration near the bottom of that page for details.

You might need to diable cURL in the module config options in the Introjucer to avoid linker errors if you’re on Windows. I should probably disable that by default actually.

Hamm thanks Dave…
It’s all working and I got that things how it work with Juce…
It’s quite easy to put(Actually I tried with latest module based Juce first time :wink: {sorry Juce})

Thanks to Jules for making all very easy to use though it is changed.
Hey Jules … One thing comes to mind is if there are such modules people have made for Juce, We should have list of all such in forum here. I think it can help surfing such new development will be easy with your new technology.
If all modules are listed than it’s fine, but if not I request Jules to create one thread for it and also i request module Author to provide their module details on that thread.

Thanks you such all authors, for doing such a nice work.

Hi Dave, thanks for developing such a great module! I'm having a bit of trouble with the setLoopBetweenTimes method. I have similar code as your comment above, but with this small modification in my implementation:

audioDeviceManager.initialise (0, 2, nullptr, true); 
audioDeviceManager.addAudioCallback (&audioSourcePlayer); 
audioSourcePlayer.setSource (&audioFilePlayer); 
audioFilePlayer.setFile ("<some path to file>");
 /***/ audioFilePlayer.setLoopTimes(startTime, endTime);
 /***/ audioFilePlayer.setLoopBetweenTimes(true);

Should playback automatically start after calling setLoopBetweenTimes() ? I'm currently not getting any sound, and I have confirmed that my start and end times are valid, and that getLoopBetweenTimes() returns true. I've also tried calling start() after the last line. Thanks!

It's a bit difficult to tell from that code snippet. You wouldn't normally set the file and loop times long with the audio device manager set-up so perhaps the file isn't being loaded correctly?

Take a look at the dRowAudio Demo app in the repo, that can loop the playing file by moving the red marker on the whole file preview (and you have to turn it on from the top right buttons).

Thanks, everything's working now. I'm not entirely sure what the problem was, but I separated the device manager set up from setting and toggling the loop times (and used buttons like in the demo).

I'm trying to implement a file player with a FileListComponent supplying the files to play. Everything works fine when I play wav files that are 44.1, but 48k are playing back slow. This doesn't happen when I play the same files through the dRowAudio demo. I'm looking through the source, but not finding why it works fine there but not in my code.

I must be missing something simple. Any suggestions?

The drowaudio module has a lot of great stuff -- thanks.

I'm having the same problem as ctrestain (post #8 in this thread):

I'm trying to implement a file player with a FileListComponent supplying the files to play. Everything works fine when I play wav files that are 44.1, but 48k are playing back slow.

When I play a .WAV file recorded at a 22K sample rate using the code below, it plays back at 44K (sounding like a chipmunk).  Shouldn't AudioFilePlayer be getting the .WAV file's sample rate from the file, and then doing appropriate sample-rate conversion?

drow::AudioFilePlayer drowAudioFilePlayer;


drowAudioFilePlayer.setFile ( dir + "sound0.wav" );


Am I forgetting to make some needed call?


In case it may help, I had a similar problem in my own code a while back, and found that it was necessary to explicitly pass the sample rate as a parameter to AudioTransportSource in the call to transport->setSource.  (See last line of code below.)  The 4th argument must give the sample rate; if it is zero, no sample-rate conversion is performed.

MemoryInputStream*       memStream;    // data stream from .WAV file image

AudioFormatReader*       reader;       // turns file (eg .wav) into stream of audio samples

AudioFormatReaderSource* audioSource;  // Reads the audio data.

AudioTransportSource*    transport;    // Manages the playback of an audio source, SR conv.


memStream = new MemoryInputStream (audioDataAddr, audioDataSize, false ); 

WavAudioFormat wavFormat;

reader = wavFormat.createReaderFor (memStream, false);

audioSource = new AudioFormatReaderSource( reader, false );

transport = new AudioTransportSource();

transport->setSource( audioSource, 0, nullptr, reader->sampleRate );


Thanks, must have missed that as I use the AudioFilePlayerExt in the demo. Should be sorted now.

I downloaded your new version of the drowaudio module, and verified that playback is at the right sampling rate now.  

Thanks for the quick response.