Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "PiraTimer.h"
- #include <stdio.h>
- #include <stdlib.h>
- #define OLC_PGE_APPLICATION
- #include "olcPixelGameEngine.h"
- #include "olcPGEX_Media.h"
- #include "video_reader.h"
- struct media_info {
- std::string name;
- bool open_video;
- bool open_audio;
- };
- std::vector<media_info> medias{
- {"assets/bispoos_gameplay.mp4", true, true},
- {"assets/robot_gameplay.mp4", true, true},
- {"assets/nokia_combat.gif", true, true},
- {"assets/winter.ogg", true, true},
- {"assets/skeleton.mp4", true, true},
- {"assets/shooter.mp4", true, true}
- };
- // Override base class with your custom functionality
- class Example : public olc::PixelGameEngine
- {
- public:
- olc::Media media;
- olc::Decal* frame;
- int idx = 0;
- public:
- Example()
- {
- // Name your application
- sAppName = "Example";
- }
- public:
- bool OpenNextVideo() {
- idx = (idx + 1) % medias.size();
- printf("Playing sound[%i]: %s\n", idx, medias[idx].name.c_str());
- if (media.Open(medias[idx].name.c_str(), medias[idx].open_video, medias[idx].open_audio) == olc::MediaResult::Error)
- return false;
- }
- bool OpenPrevVideo() {
- idx = (idx + medias.size() - 1) % medias.size();
- printf("Playing sound[%i]: %s\n", idx, medias[idx].name.c_str());
- if (media.Open(medias[idx].name.c_str(), medias[idx].open_video, medias[idx].open_audio) == olc::MediaResult::Error)
- return false;
- }
- bool OpenCurrVideo() {
- printf("Playing sound[%i]: %s\n", idx, medias[idx].name.c_str());
- if (media.Open(medias[idx].name.c_str(), medias[idx].open_video, medias[idx].open_audio) == olc::MediaResult::Error)
- return false;
- }
- bool OnUserCreate() override
- {
- OpenCurrVideo();
- return true;
- }
- bool OnUserUpdate(float delta_time) override
- {
- if (GetKey(olc::ESCAPE).bPressed) {
- return false;
- }
- if (GetKey(olc::ENTER).bPressed) {
- frame = media.GetVideoFrame();
- }
- if (GetKey(olc::S).bPressed) {
- if (media.SkipVideoFrame() == olc::MediaResult::Success)
- printf("Sucesfully skipped\n");
- }
- if (GetKey(olc::SPACE).bHeld) {
- frame = media.GetVideoFrame();
- }
- if (GetKey(olc::M).bPressed) {
- OpenNextVideo();
- }
- if (GetKey(olc::N).bPressed) {
- OpenPrevVideo();
- }
- if (GetKey(olc::B).bPressed) {
- OpenCurrVideo();
- }
- if (GetKey(olc::V).bPressed) {
- media.Close();
- }
- if (media.IsVideoOpened()) {
- frame = media.GetVideoFrame(delta_time);
- if (frame != nullptr)
- DrawDecal({ 0,0 }, frame);
- //else
- //return false;
- }
- using namespace std::string_literals;
- DrawStringPropDecal(
- { 5,5 },
- "M - open next\n"
- "N - open prev\n"
- "B - open curr\n"
- "V - close curr\n"
- "video: "s + (medias[idx].open_video ? "on\n" : "off\n") +
- "audio: "s + (medias[idx].open_audio ? "on\n" : "off\n"),
- olc::RED,
- {3,3}
- );
- PiraTimer::end("InternalUpdate");
- PiraTimer::end("FrameLength");
- PiraTimer::start("FrameLength");
- PiraTimer::start("OnUserUpdate");
- PiraTimer::start("GetFrame");
- //if (media.FinishedReading()) {
- // return false;
- //}
- //std::this_thread::sleep_for(std::chrono::milliseconds(200));
- //if (olc::MediaResult::Success != media.SkipVideoFrame())
- // return false;
- PiraTimer::end("GetFrame");
- PiraTimer::end("OnUserUpdate");
- PiraTimer::start("InternalUpdate");
- return true;
- }
- };
- int main()
- {
- {
- Example demo;
- if (demo.Construct(1280, 720, 1, 1))
- demo.Start();
- }
- PiraTimer::print_stats();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement