Compare commits
2 Commits
e36520b310
...
0f94cbaa9f
Author | SHA1 | Date | |
---|---|---|---|
0f94cbaa9f | |||
fcaba07e09 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,5 @@
|
||||
/build/
|
||||
.cache/
|
||||
/enc_temp_folder
|
||||
/out/build/x64-Debug
|
||||
/.vs
|
||||
|
@ -69,7 +69,69 @@ IF(UNIX)
|
||||
)
|
||||
|
||||
ELSE(WIN32)
|
||||
set(ENV{http_proxy} "http://127.0.0.1:10809")
|
||||
set(ENV{https_proxy} "http://127.0.0.1:10809")
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(SFML
|
||||
GIT_REPOSITORY https://github.com/SFML/SFML.git
|
||||
GIT_TAG 2.6.x
|
||||
)
|
||||
FetchContent_MakeAvailable(SFML)
|
||||
|
||||
#vcpkg
|
||||
set(VCPKG_PACKAGE C:/document/lib/vcpkg/packages)
|
||||
set(VCPKG_BUILDTREES_DIR C:/document/lib/vcpkg/buildtrees)
|
||||
|
||||
#ffmpeg
|
||||
include_directories(${VCPKG_PACKAGE}/ffmpeg_x64-windows/include)
|
||||
file(GLOB_RECURSE FFMPEG_LIBS ${VCPKG_PACKAGE}/ffmpeg_x64-windows/debug/lib/*.lib)
|
||||
|
||||
add_executable(${PROJECT_N}
|
||||
main.cc
|
||||
${srcs}
|
||||
)
|
||||
target_link_libraries(${PROJECT_N} PRIVATE
|
||||
sfml-system
|
||||
sfml-window
|
||||
sfml-graphics
|
||||
sfml-network
|
||||
sfml-audio
|
||||
${FFMPEG_LIBS}
|
||||
spdlog
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_N_T}
|
||||
${srcs}
|
||||
${tests}
|
||||
)
|
||||
target_link_libraries(${PROJECT_N_T} PRIVATE
|
||||
sfml-system
|
||||
sfml-window
|
||||
sfml-graphics
|
||||
sfml-network
|
||||
sfml-audio
|
||||
|
||||
GTest::gtest_main
|
||||
)
|
||||
|
||||
add_custom_target(run
|
||||
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_N} ./img/ocean.jpg
|
||||
DEPENDS ${PROJECT_N}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
COMMENT "Starting ${PROJECT_N}"
|
||||
)
|
||||
|
||||
add_custom_target(run_test
|
||||
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_N_T}
|
||||
DEPENDS ${PROJECT_N_T}
|
||||
WORKING_DIRECTORY ${PROJECT_CURRENT_BINARY_DIR}
|
||||
COMMENT "Starting ${PROJECT_N_T}"
|
||||
)
|
||||
add_custom_command(
|
||||
TARGET ${PROJECT_N}
|
||||
COMMENT "Copy OpenAL DLL"
|
||||
PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${SFML_SOURCE_DIR}/extlibs/bin/$<IF:$<EQUAL:${CMAKE_SIZEOF_VOID_P},8>,x64,x86>/openal32.dll $<TARGET_FILE_DIR:${PROJECT_N}>
|
||||
VERBATIM)
|
||||
ENDIF()
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(${PROJECT_N_T})
|
||||
|
@ -1,8 +1,9 @@
|
||||
#ifndef UTILTOOL_H
|
||||
#define UTILTOOL_H
|
||||
|
||||
#include <iostream>
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
enum class MediaType{
|
||||
VIDEO,
|
||||
@ -14,9 +15,9 @@ enum class MediaType{
|
||||
class UtilTool
|
||||
{
|
||||
private:
|
||||
constexpr static std::array<std::string, 2> ImageTypes{"jpg","png"};
|
||||
constexpr static std::array<std::string, 1> VideoTypes{"mp4"};
|
||||
constexpr static std::array<std::string, 1> AudioTypes{"mp3"};
|
||||
constexpr static std::array<std::string_view, 2> ImageTypes{"jpg","png"};
|
||||
constexpr static std::array<std::string_view, 1> VideoTypes{"mp4"};
|
||||
constexpr static std::array<std::string_view, 1> AudioTypes{"mp3"};
|
||||
static bool CheckFileIsImage(const std::string& filename);
|
||||
static bool CheckFileIsAudio(const std::string& filename);
|
||||
static bool CheckFileIsVideo(const std::string& filename);
|
||||
|
67
main.cc
67
main.cc
@ -6,42 +6,45 @@
|
||||
#include <SFML/Window.hpp>
|
||||
#include <cstdio>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include "UtilTool.h"
|
||||
#include "mediaService.h"
|
||||
#include "SFML/Window/VideoMode.hpp"
|
||||
|
||||
#define DEBUG
|
||||
|
||||
using namespace std::string_view_literals;
|
||||
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;
|
||||
int main(int argc, char** argv){
|
||||
auto filename = R"(C:/document/project/mp-sfml/img/ocean.mp4)"sv;
|
||||
spdlog::info("Current WorkDir Is: {}",argv[0]);
|
||||
#ifdef DEBUG
|
||||
#else
|
||||
filename = argv[1];
|
||||
if(argc != 2){
|
||||
spdlog::error("Usage: mp filename ");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
spdlog::info("filename: {}", filename);
|
||||
MediaService mediaService(filename.data(), CLIENT_WIDTH, CLIENT_HEIGHT);
|
||||
std::shared_ptr<sf::RenderWindow> window = std::make_shared<sf::RenderWindow>(sf::VideoMode(CLIENT_WIDTH, CLIENT_HEIGHT), "mp");
|
||||
mediaService.SetWindow(window);
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user