diff --git a/src/Sources/OMXPlayerCache.cpp b/src/Sources/OMXPlayerCache.cpp new file mode 100644 index 0000000..5c12292 --- /dev/null +++ b/src/Sources/OMXPlayerCache.cpp @@ -0,0 +1,42 @@ +#include "OMXPlayerCache.h" + +namespace ofx { +namespace piMapper { + +OMXPlayerCache * OMXPlayerCache::_instance = 0; + +OMXPlayerCache * OMXPlayerCache::instance(){ + if(_instance == 0){ + _instance = new ofx::piMapper::OMXPlayerCache(); + } + return _instance; +} + +ofxOMXPlayer * OMXPlayerCache::load(string moviePath){ + if(_players.find(moviePath) == _players.end()){ + ofxOMXPlayerSettings settings; + settings.videoPath = moviePath; + settings.useHDMIForAudio = true; + settings.enableTexture = true; + settings.enableLooping = true; + settings.enableAudio = VideoSource::enableAudio; + + ofxOMXPlayer * p = new ofxOMXPlayer(); + p->setup(settings); + _players.push_back(p); + + return p; + } + + _players[moviePath]->restartMovie(); + return _players[moviePath]; +} + +void OMXPlayerCache::unload(string moviePath){ + if(_players.find(moviePath) != _players.end()){ + _players[moviePath]->setPaused(true); + } +} + +} // namespace piMapper +} // namespace ofx \ No newline at end of file diff --git a/src/Sources/OMXPlayerCache.h b/src/Sources/OMXPlayerCache.h new file mode 100644 index 0000000..7949a77 --- /dev/null +++ b/src/Sources/OMXPlayerCache.h @@ -0,0 +1,23 @@ +#pragma once + +#include "ofMain.h" +#include "ofxOMXPlayer.h" + +namespace ofx { +namespace piMapper { + +class OMXPlayerCache { + + public: + static OMXPlayerCache * instance(); + ofxOMXPlayer * load(string moviePath); + void unload(string moviePath); + + private: + static OMXPlayerCache * _instance; + map _players; + +}; + +} // namespace piMapper +} // namespace ofx