#ifndef GLTEST_AUDIOPLAYER_H
#define GLTEST_AUDIOPLAYER_H

#include "ISndSource.h"
#include <portaudio.h>
#include <string>
#include <functional>

class AudioPlayer {
private:
	ISndSource* _sndSource;
	PaStream* _stream;

	typedef std::function<void(float*,std::size_t,std::size_t,std::size_t)> StreamListenerType;
	typedef std::function<void()> StreamFinishedType;

	StreamListenerType _streamListener;
	StreamFinishedType _streamFinishedLitener;

public:
	AudioPlayer(std::string path);
	~AudioPlayer();
	void play();
	void stop();
	void setStreamListener(StreamListenerType callback);
	void setStreamFinishedListener(StreamFinishedType callback);
	int streamCallback(const void* input,
	                   void* output,
	                   unsigned long framesPerBuffer,
	                   const PaStreamCallbackTimeInfo *timeInfo,
	                   PaStreamCallbackFlags flags);
	void streamFinishedCallback();

private:
	ISndSource* openSoundFile(std::string path);
};


#endif //GLTEST_AUDIOPLAYER_H
