From fee5b5558ce0f789460ce6947fec082eb84129a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=82=E1=85=A1=E1=86=B7=E1=84=8C=E1=85=A5=E1=86=BC?= =?UTF-8?q?=E1=84=92=E1=85=A9?= Date: Fri, 25 Oct 2019 22:59:30 +0900 Subject: [PATCH] Add video restart/pause/resume method --- src/Application/Application.cpp | 12 ++++++++++++ src/Application/Application.h | 5 +++++ src/MediaServer/MediaServer.cpp | 26 ++++++++++++++++++++++++++ src/MediaServer/MediaServer.h | 4 ++++ src/Sources/VideoSource.cpp | 24 ++++++++++++++++++++++++ src/Sources/VideoSource.h | 3 +++ src/ofxPiMapper.cpp | 12 ++++++++++++ src/ofxPiMapper.h | 5 +++++ 8 files changed, 91 insertions(+) diff --git a/src/Application/Application.cpp b/src/Application/Application.cpp index 10e5476..6746547 100644 --- a/src/Application/Application.cpp +++ b/src/Application/Application.cpp @@ -641,5 +641,17 @@ void Application::toggleLayerPanel(){ } } +void Application::restart(){ + _mediaServer.restart(); +} + +void Application::pause(){ + _mediaServer.pause(); +} + +void Application::resume(){ + _mediaServer.resume(); +} + } // namespace piMapper } // namespace ofx diff --git a/src/Application/Application.h b/src/Application/Application.h index 8f8542f..6a9794f 100644 --- a/src/Application/Application.h +++ b/src/Application/Application.h @@ -153,6 +153,11 @@ class Application { void reboot(); void shutdown(); + // video play control + void restart(); + void pause(); + void resume(); + protected: void setState(ApplicationBaseMode * st); diff --git a/src/MediaServer/MediaServer.cpp b/src/MediaServer/MediaServer.cpp index 8b22544..37d77cb 100644 --- a/src/MediaServer/MediaServer.cpp +++ b/src/MediaServer/MediaServer.cpp @@ -50,6 +50,32 @@ void MediaServer::draw(){ } } +void MediaServer::restart() { + typedef map ::iterator it_type; + for(it_type i = loadedSources.begin(); i != loadedSources.end(); i++){ + if(i->second->getType() == SourceType::SOURCE_TYPE_VIDEO){ + static_cast (i->second)->restart(); + } + } +} +void MediaServer::pause() { + typedef map ::iterator it_type; + for(it_type i = loadedSources.begin(); i != loadedSources.end(); i++){ + if(i->second->getType() == SourceType::SOURCE_TYPE_VIDEO){ + static_cast (i->second)->pause(); + } + } +} +void MediaServer::resume() { + typedef map ::iterator it_type; + for(it_type i = loadedSources.begin(); i != loadedSources.end(); i++){ + if(i->second->getType() == SourceType::SOURCE_TYPE_VIDEO){ + static_cast (i->second)->resume(); + } + } +} + + int MediaServer::getNumImages(){ return imageWatcher.getFilePaths().size(); diff --git a/src/MediaServer/MediaServer.h b/src/MediaServer/MediaServer.h index 51bf721..8962895 100644 --- a/src/MediaServer/MediaServer.h +++ b/src/MediaServer/MediaServer.h @@ -52,6 +52,10 @@ class MediaServer { void update(); void draw(); + void restart(); + void pause(); + void resume(); + int getNumVideos(); int getNumImages(); int getNumFboSources(); // new diff --git a/src/Sources/VideoSource.cpp b/src/Sources/VideoSource.cpp index fc0df92..72e1092 100644 --- a/src/Sources/VideoSource.cpp +++ b/src/Sources/VideoSource.cpp @@ -106,5 +106,29 @@ void VideoSource::stop(){ } #endif +void VideoSource::restart(){ + #ifdef TARGET_RASPBERRY_PI + _omxPlayer->restartMovie(); + #else + _videoPlayer->setPosition(0); + _videoPlayer->play(); + #endif +} + +void VideoSource::pause() { + #ifdef TARGET_RASPBERRY_PI + _omxPlayer->setPaused(true); + #else + _videoPlayer->setPaused(true); + #endif +} +void VideoSource::resume() { + #ifdef TARGET_RASPBERRY_PI + _omxPlayer->setPaused(false); + #else + _videoPlayer->setPaused(false); + #endif +} + } // namespace piMapper } // namespace ofx diff --git a/src/Sources/VideoSource.h b/src/Sources/VideoSource.h index d0cea99..f1af7d3 100644 --- a/src/Sources/VideoSource.h +++ b/src/Sources/VideoSource.h @@ -30,6 +30,9 @@ class VideoSource : public BaseSource { void togglePause(); void stop(); void update(ofEventArgs & args); + void restart(); + void pause(); + void resume(); private: diff --git a/src/ofxPiMapper.cpp b/src/ofxPiMapper.cpp index e8bb1e4..e2131e3 100644 --- a/src/ofxPiMapper.cpp +++ b/src/ofxPiMapper.cpp @@ -284,3 +284,15 @@ ofx::piMapper::Mode ofxPiMapper::getMode(){ void ofxPiMapper::toggleLayerPanel(){ _application.toggleLayerPanel(); } + +void ofxPiMapper::restart() { + _application.restart(); +} + +void ofxPiMapper::pause() { + _application.pause(); +} + +void ofxPiMapper::resume() { + _application.resume(); +} diff --git a/src/ofxPiMapper.h b/src/ofxPiMapper.h index 1271dd8..2797f46 100644 --- a/src/ofxPiMapper.h +++ b/src/ofxPiMapper.h @@ -94,6 +94,11 @@ class ofxPiMapper { void reboot(); void shutdown(); + // video play control + void restart(); + void pause(); + void resume(); + private: ofx::piMapper::Application _application; };