# AudioThumbnail

**URL:** <https://forum.juce.com/t/audiothumbnail/6610>\
**Category:** General JUCE discussion\
**Created:** [March 22, 2011, 2:44am UTC](https://forum.juce.com/t/audiothumbnail/6610 "2011-03-22T02:44:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sharky101](https://avatars.discourse-cdn.com/v4/letter/s/f19dbf/32.png) [@Sharky101](https://forum.juce.com/u/Sharky101)\
**Post date:** [March 22, 2011, 2:44am UTC](https://forum.juce.com/t/audiothumbnail/6610/1 "2011-03-22T02:44:59Z")

</div>

I have currently got an Audio player with pitch, gain, track bar, play and pause. I wish to add a graphical representation of the track loaded into my FilenameComponent so the track bar will sit under it.  
I had a quick look around and found the audio juce demo and the AudioThumbnail class.

I am quite new to juce so my abilities are still in the learning phase 🙂 Please bare with me.  
I am struggling to get the thumb nails to work.

in my header file :

`	AudioThumbnail *audioImage;
	AudioFormatManager *formatManager;
        AudioThumbnailCache *thumbnailCache;`

then in my cpp:

`	thumbnailCache = new AudioThumbnailCache(2);
	audioImage = new AudioThumbnail (512, *formatManager, *thumbnailCache);
	audioImage->setSource(???audio file???); //not sure what goes here :-)`

i assumed the replacement for ???audiofile??? would be —currentAudioFileSource— from below :

[code]void Player::filenameComponentChanged (FilenameComponent\* filenameComponent)  
{  
// this is called when the user changes the filename in the file chooser box  
File audioFile (filenameComponent-\>getCurrentFile().getFullPathName());

```
if(audioFile.existsAsFile())
{
	// unload the previous file source and delete it..
	transportSource.stop();
	transportSource.setSource (0);
	deleteAndZero (currentAudioFileSource);
	
	// create a new file source from the file..
	// get a format manager and set it up with the basic types (wav, ogg and aiff).
	AudioFormatManager formatManager;
	formatManager.registerBasicFormats();
	
	AudioFormatReader* reader = formatManager.createReaderFor (audioFile);
	
	if (reader != 0)
	{
		currentFile = audioFile;
		currentAudioFileSource = new AudioFormatReaderSource (reader, true);
		
		// ..and plug it into our transport source
		transportSource.setSource (currentAudioFileSource,
								   32768, // tells it to buffer this many samples ahead
								   reader->sampleRate);
	}
	totalPosLength = transportSource.getTotalLength();
	//std::cout << "totalPosLength =" << totalPosLength << "\n";
//	sampleLength = totalPosLength;
//	std::cout << "sample length =" << sampleLength << "\n";
	updateButtons();
}
else
{
	AlertWindow::showMessageBox (AlertWindow::WarningIcon,
								 T(PROJECT_NAME),
								 T("Couldn't open file!\n\n"));
}	

```

}  
[/code]  
Then in void Paint () I have:

`	audioImage->drawChannel (g, 10, 10, getWidth(), 
							getHeight(), 0, audioImage->getTotalLength(), 
							0, 1.0f);`

Sorry if I am totally off track 🙂 Like I said I’m pretty new to this 🙂
