抽象多媒体类, 修复gtest问题
This commit is contained in:
@@ -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
22
src/mediaService.cc
Normal 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
2
src/stream.cc
Normal file
@@ -0,0 +1,2 @@
|
||||
#include "stream.h"
|
||||
|
||||
Reference in New Issue
Block a user