Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Reputeless
Created May 8, 2022 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Reputeless/3d527302d459792f7a5e1094d30d0529 to your computer and use it in GitHub Desktop.
Save Reputeless/3d527302d459792f7a5e1094d30d0529 to your computer and use it in GitHub Desktop.
# include <Siv3D.hpp> // OpenSiv3D v0.6.3
VideoTexture LoadVideoFromResource(const FilePathView resourcePath, const FilePathView temporaryFilePath, const Loop loop)
{
# if SIV3D_PLATFORM(WINDOWS)
if (not FileSystem::Exists(temporaryFilePath))
{
Print << U"ファイルをコピー";
BinaryReader reader{ resourcePath };
if (not reader)
{
return{};
}
BinaryWriter writer{ temporaryFilePath };
int64 copySize = reader.size();
constexpr int64 BlockSize = (1024 * 64);
Array<Byte> buffer(BlockSize);
while (copySize)
{
const int64 readSize = Min(copySize, BlockSize);
reader.read(buffer.data(), readSize);
writer.write(buffer.data(), readSize);
copySize -= readSize;
}
}
else
{
Print << U"キャッシュが存在";
}
return VideoTexture{ temporaryFilePath, loop };
# else
return VideoTexture{ resourcePath, loop };
# endif
}
void Main()
{
const FilePath resourcePath = Resource(U"example/video/river.mp4");
const FilePath temporaryFilePath = (FileSystem::TemporaryDirectoryPath() + U"MyApp/river.mp4");
Print << resourcePath;
Print << temporaryFilePath;
const VideoTexture videoTexture = LoadVideoFromResource(resourcePath, temporaryFilePath, Loop::Yes);
while (System::Update())
{
videoTexture.advance();
videoTexture.scaled(0.5).draw();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment