抽象多媒体类, 修复gtest问题

This commit is contained in:
Jie
2024-09-09 13:20:59 +08:00
parent 628b95d37d
commit 7c049db4ac
10 changed files with 166 additions and 31 deletions

View File

@@ -1,15 +1,58 @@
#include "UtilTool.h"
#include <filesystem>
bool UtilTool::CheckFileIsImage(const std::string& filepath){
//简单实现, 通过后缀判断
bool UtilTool::CheckFileIsImage(const std::string &filepath)
{
// 简单实现, 通过后缀判断
auto path = std::filesystem::path(filepath);
auto su = path.extension().string();
for(const auto& type : ImageType){
if (su.find(type) != std::string::npos){
for (const auto &type : ImageTypes)
{
if (su.find(type) != std::string::npos)
{
return true;
}
}
return false;
}
bool UtilTool::CheckFileIsVideo(const std::string &filepath)
{
// 简单实现, 通过后缀判断
auto path = std::filesystem::path(filepath);
auto su = path.extension().string();
for (const auto &type : VideoTypes)
{
if (su.find(type) != std::string::npos)
{
return true;
}
}
return false;
}
bool UtilTool::CheckFileIsAudio(const std::string &filepath)
{
// 简单实现, 通过后缀判断
auto path = std::filesystem::path(filepath);
auto su = path.extension().string();
for (const auto &type : AudioTypes)
{
if (su.find(type) != std::string::npos)
{
return true;
}
}
return false;
}
MediaType UtilTool::CheckFileType(const std::string &filepath)
{
if (CheckFileIsImage(filepath))
return MediaType::IMAGE;
if (CheckFileIsAudio(filepath))
return MediaType::AUDIO;
if (CheckFileIsVideo(filepath))
return MediaType::VIDEO;
return MediaType::UNSUPPORT;
}

22
src/mediaService.cc Normal file
View File

@@ -0,0 +1,22 @@
#include <mediaService.h>
MediaService::MediaService(const std::string& filename, int width, int height){
auto type = UtilTool::CheckFileType(filename);
client_width = width;
client_height = height;
float scale = .0f;
switch (type)
{
case MediaType::IMAGE:
imageService = new ImageService(filename);
texture = &imageService->GetTexture();
sprite = new sf::Sprite();
sprite->setTexture(*texture);
scale = imageService->GetScale(client_width, client_height);
sprite->setScale(scale, scale);
break;
default:
break;
}
}

2
src/stream.cc Normal file
View File

@@ -0,0 +1,2 @@
#include "stream.h"