16
SFML projects / SFMLTheora 1.3 - Play videos in SFML
« on: April 15, 2011, 07:25:35 pm »
Nope it still stutters for me with the latest update
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
bool PlayVideo(std::string name)
{
auto viddy = std::make_shared<SFMLTheora::Video>();
if(!viddy)return false;
viddy->LoadClip(name);
//viddy->SetX(0);
//viddy->SetY(0);
GLRenderer::GetInstance()->GetMainWindow()->EnableVerticalSync(true);
bool result = true;
bool stopvideo = false;
while(!viddy->IsDone())
{
sf::Event sfEvent;
while(GLRenderer::GetInstance()->GetMainWindow()->PollEvent(sfEvent))
{
if(sfEvent.Type == sf::Event::Closed){result = false; stopvideo = true; break;}
if((sfEvent.Type == sf::Event::KeyPressed) && (sfEvent.Key.Code == sf::Key::Escape))
{
viddy->Stop();
//viddy->SetAudioGain(0.0f);
result = true;
stopvideo = true;
break;
}
if ((sfEvent.Type == sf::Event::KeyPressed) && (sfEvent.Key.Code == sf::Key::F12))Screenshot();
}
if(stopvideo)break;
viddy->Resize(IniOptions::GetInstance()->window_width, IniOptions::GetInstance()->window_height);
viddy->Update(GLRenderer::GetInstance()->GetMainWindow()->GetFrameTime());
GLRenderer::GetInstance()->GetMainWindow()->Clear();
GLRenderer::GetInstance()->GetMainWindow()->Draw(*viddy);
GLRenderer::GetInstance()->GetMainWindow()->Display();
}
if(IniOptions::GetInstance()->vsync)GLRenderer::GetInstance()->GetMainWindow()->EnableVerticalSync(true);
else GLRenderer::GetInstance()->GetMainWindow()->EnableVerticalSync(false);
return result;
}
void WindowImplWin32::SetTitle(const std::string& title)
{
SetWindowText(myHandle, title.c_str());
}
bool PlayVideo(std::string name)
{
auto viddy = std::make_shared<SFMLTheora::Video>();
if(!viddy)return false;
viddy->LoadClip(name);
//viddy->SetX(0);
//viddy->SetY(0);
//GLR->GetMainWindow()->UseVerticalSync(true);
bool result = true;
bool stopvideo = false;
while(!viddy->GetVideoClip()->isDone())
{
sf::Event sfEvent;
while(GLRenderer::GetInstance()->GetMainWindow()->PollEvent(sfEvent))
{
if(sfEvent.Type == sf::Event::Closed){result = false; stopvideo = true; break;}
if((sfEvent.Type == sf::Event::KeyPressed) && (sfEvent.Key.Code == sf::Key::Escape))
{
viddy->GetVideoClip()->stop();
viddy->GetVideoClip()->setAudioGain(0.0f);
result = true;
stopvideo = true;
break;
}
if ((sfEvent.Type == sf::Event::KeyPressed) && (sfEvent.Key.Code == sf::Key::F12))Screenshot();
}
if(stopvideo)break;
viddy->Update(GLRenderer::GetInstance()->GetMainWindow()->GetFrameTime());
viddy->Resize(IniOptions::GetInstance()->window_width, IniOptions::GetInstance()->window_height);
GLRenderer::GetInstance()->GetMainWindow()->Clear();
GLRenderer::GetInstance()->GetMainWindow()->Draw(*viddy);
GLRenderer::GetInstance()->GetMainWindow()->Display();
}
//if(!options.vsync)GLR->GetMainWindow()->UseVerticalSync(false);
return result;
}