mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
* windows video player uses the new FS
* don't crash on missing sounds
This commit is contained in:
@@ -134,24 +134,24 @@ Mix_Chunk *CSoundHandler::GetSoundChunk(soundBase::soundID soundID)
|
|||||||
boost::bimap<soundBase::soundID, std::string>::left_iterator it;
|
boost::bimap<soundBase::soundID, std::string>::left_iterator it;
|
||||||
it = sounds.left.find(soundID);
|
it = sounds.left.find(soundID);
|
||||||
if (it == sounds.left.end())
|
if (it == sounds.left.end())
|
||||||
return NULL;
|
return nullptr;
|
||||||
|
|
||||||
// Load and insert
|
// Load and insert
|
||||||
auto data = CResourceHandler::get()->loadData(ResourceID(std::string("SOUNDS/") + it->second, EResType::SOUND));
|
try
|
||||||
|
|
||||||
SDL_RWops *ops = SDL_RWFromMem(data.first.release(), data.second);
|
|
||||||
Mix_Chunk *chunk;
|
|
||||||
chunk = Mix_LoadWAV_RW(ops, 1); // will free ops
|
|
||||||
|
|
||||||
if (!chunk)
|
|
||||||
{
|
{
|
||||||
tlog1 << "Unable to mix sound" << it->second << "(" << Mix_GetError() << ")" << std::endl;
|
auto data = CResourceHandler::get()->loadData(ResourceID(std::string("SOUNDS/") + it->second, EResType::SOUND));
|
||||||
return NULL;
|
|
||||||
|
SDL_RWops *ops = SDL_RWFromMem(data.first.release(), data.second);
|
||||||
|
Mix_Chunk *chunk;
|
||||||
|
chunk = Mix_LoadWAV_RW(ops, 1); // will free ops
|
||||||
|
soundChunks.insert(std::pair<soundBase::soundID, Mix_Chunk *>(soundID, chunk));
|
||||||
|
return chunk;
|
||||||
|
}
|
||||||
|
catch(std::exception &e)
|
||||||
|
{
|
||||||
|
tlog3 << "Cannot get sound " << soundID << " chunk: " << e.what() << "\n";
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
soundChunks.insert(std::pair<soundBase::soundID, Mix_Chunk *>(soundID, chunk));
|
|
||||||
|
|
||||||
return chunk;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a soundID given a filename
|
// Get a soundID given a filename
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ void checkForError(bool throwing = true)
|
|||||||
LocalFree( pTemp );
|
LocalFree( pTemp );
|
||||||
pTemp = NULL;
|
pTemp = NULL;
|
||||||
if(throwing)
|
if(throwing)
|
||||||
throw msg;
|
throw std::runtime_error(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void blitBuffer(char *buffer, int x, int y, int w, int h, SDL_Surface *dst)
|
void blitBuffer(char *buffer, int x, int y, int w, int h, SDL_Surface *dst)
|
||||||
@@ -161,8 +161,8 @@ bool CBIKHandler::open(std::string name)
|
|||||||
checkErrorAndClean:
|
checkErrorAndClean:
|
||||||
CloseHandle(hBinkFile);
|
CloseHandle(hBinkFile);
|
||||||
hBinkFile = NULL;
|
hBinkFile = NULL;
|
||||||
checkForError(false);
|
checkForError();
|
||||||
return false;
|
throw std::runtime_error("BIK failed opening video!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBIKHandler::show( int x, int y, SDL_Surface *dst, bool update )
|
void CBIKHandler::show( int x, int y, SDL_Surface *dst, bool update )
|
||||||
@@ -302,8 +302,8 @@ bool CSmackPlayer::open( std::string name )
|
|||||||
if (!data)
|
if (!data)
|
||||||
{
|
{
|
||||||
tlog1 << "Smack cannot open " << name << std::endl;
|
tlog1 << "Smack cannot open " << name << std::endl;
|
||||||
checkForError(false);
|
checkForError();
|
||||||
return false;
|
throw std::runtime_error("SMACK failed opening video");
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = new char[data->width*data->height*2];
|
buffer = new char[data->width*data->height*2];
|
||||||
@@ -395,9 +395,6 @@ void CSmackPlayer::redraw( int x, int y, SDL_Surface *dst, bool update )
|
|||||||
|
|
||||||
CVideoPlayer::CVideoPlayer()
|
CVideoPlayer::CVideoPlayer()
|
||||||
{
|
{
|
||||||
vidh.add_file(std::string(GameConstants::DATA_DIR + "/Data/VIDEO.VID"));
|
|
||||||
vidh.add_file(std::string(GameConstants::DATA_DIR + "/Data/H3ab_ahd.vid"));
|
|
||||||
|
|
||||||
current = NULL;
|
current = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -415,24 +412,31 @@ bool CVideoPlayer::open(std::string name)
|
|||||||
fname = name;
|
fname = name;
|
||||||
first = true;
|
first = true;
|
||||||
|
|
||||||
//extract video from video.vid so we can play it
|
try
|
||||||
bool opened = false;
|
|
||||||
vidh.extract(name, name);
|
|
||||||
if (boost::filesystem::exists(name))
|
|
||||||
opened = current->open(name);
|
|
||||||
else // couldn't load video then load from ab resource file
|
|
||||||
{
|
{
|
||||||
vidh.extract(name, name);
|
// Extract video from video.vid so we can play it.
|
||||||
if (boost::filesystem::exists(name))
|
// We can handle only videos in form of single file, no archive support yet.
|
||||||
opened = current->open(name);
|
{
|
||||||
|
auto myVideo = CResourceHandler::get()->load(ResourceID("VIDEO/" + name, EResType::VIDEO));
|
||||||
|
|
||||||
|
unique_ptr<char[]> data = unique_ptr<char[]>(new char[myVideo->getSize()]);
|
||||||
|
myVideo->read((ui8*)data.get(), myVideo->getSize());
|
||||||
|
|
||||||
|
std::ofstream out(name, std::ofstream::binary);
|
||||||
|
out.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||||
|
out.write(data.get(), myVideo->getSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
current->open(name);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
if(!opened) // check if video could be loaded
|
catch(std::exception &e)
|
||||||
{
|
{
|
||||||
current = NULL;
|
current = nullptr;
|
||||||
tlog3 << "Failed to open video file " << name << std::endl;
|
tlog3 << "Failed to open video file " << name << ": " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return opened;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CVideoPlayer::close()
|
void CVideoPlayer::close()
|
||||||
|
|||||||
Reference in New Issue
Block a user