mp-sfml/main.cc
2024-10-08 14:34:52 +08:00

48 lines
1.3 KiB
C++

#include "UtilTool.h"
#include "mediaService.h"
#include <SFML/Graphics.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <cstdio>
#include <spdlog/spdlog.h>
#define DEBUG
constexpr int CLIENT_WIDTH = 800;
constexpr int CLIENT_HEIGHT = 600;
int main(int argc, char **argv) {
spdlog::info("Current WorkDir Is: {}", argv[0]);
#ifdef DEBUG
argv[1] = R"(../img/ocean.mp4)";
#else
if (argc != 2) {
spdlog::error("Usage: mp filename ");
return 0;
}
#endif
spdlog::info("filename: {}", argv[1]);
std::shared_ptr<sf::RenderWindow> window =
std::make_shared<sf::RenderWindow>(
sf::VideoMode(CLIENT_WIDTH, CLIENT_HEIGHT), "mp");
MediaService mediaService(window, argv[1], CLIENT_WIDTH, CLIENT_HEIGHT);
bool running = true;
while (running) {
sf::Event event;
while (window->pollEvent(event)) {
if (event.type == sf::Event::Closed) {
running = false;
}
if (event.type == sf::Event::KeyPressed) {
if (event.key.code == sf::Keyboard::Escape) {
running = false;
}
}
}
mediaService.Play();
}
return 0;
}