Since i need to play videos with SFML and i found
this comment of Ceylo (the creator of sfeMovie)Indeed there is the feature/OpenFromStream branch. However it is not finished. It is roughly what a user from SFML forum proposed, but I don't wish to work on sfeMovie anymore so it'll have to be finished by someone else. Basically what lacks at the moment is cleanly design integration and manual tests.
And beacuse i don't want use death projects i decide to write my own video player an take advantage of libVLC, that its core is LPGL-licensed and most of its plug-ins too.
The libVLC plug-in systems works like add-ons, you carry the dlls you want without have to recompile,
so we can have both commercial and non-commercial projects.
I need to polish the final details, that includes a loadFromStream feature, then i will release the source code on github, share the MSVC 2013 libraries, and hope someone help me to create a CMAKE build system.
The players deliver a high-performance, so you won't never be worried about it.
This is an simple example showing few features:
#include <iostream>
#include <cstdio>
#include <SFML/Graphics.hpp>
#include "sf_vlc_video.hpp"
int main()
{
sf::VideoMode fullScreenMode = sf::VideoMode::getDesktopMode() ;
sf::VideoMode windowedMode = sf::VideoMode( 800 , 600 ) ;
sf::RenderWindow window( windowedMode , "Video" ) ;
window.setFramerateLimit( 60 ) ;
freopen( "null" , "w+" , stderr ) ; // Disable error/warning messaging. There are no way to fix|disable them.
SFVLC::Video video( { windowedMode.width , windowedMode.height } ) ;
video.loadFromURL( "http://video.webmfiles.org/big-buck-bunny_trailer.webm" ) ;
// Or: video.loadFromFile( "myvideo.ogv" ) ;
video.play() ;
bool isFullscreen = false ;
sf::Clock deltaClock ;
while ( window.isOpen() )
{
sf::Event event;
while ( window.pollEvent( event ) )
{
switch( event.type )
{
case sf::Event::Closed :
video.stop() ;
window.close() ;
break ;
case sf::Event::KeyPressed :
{
switch( event.key.code )
{
case sf::Keyboard::Escape : // Exit.
video.stop() ;
window.close() ;
break ;
case sf::Keyboard::Space : // Pause | Resume video with the space bar.
{
if( video.getStatus() == SFVLC::Video::Status::playing )
video.pause() ;
else
video.play() ;
break ;
}
case sf::Keyboard::F : // Resize video to fullscreen or windowed mode.
{
if( !( isFullscreen = !isFullscreen ) )
{
window.create( windowedMode , "Video" ) ;
window.setFramerateLimit( 60 ) ;
video.setSize( { windowedMode.width , windowedMode.height } ) ;
}
else
{
window.create( fullScreenMode , "Video" sf::Style::Fullscreen ) ;
window.setFramerateLimit( 60 ) ;
video.setSize( { fullScreenMode.width , fullScreenMode.height } ) ;
}
break ;
}
case sf::Keyboard::BackSpace : // Restart the video.
video.restart() ;
break ;
}
}
}
}
const float delta = deltaClock.restart().asSeconds() ;
// Inherits from sf::Transformable.
if( sf::Keyboard::isKeyPressed( sf::Keyboard::Right ) ) { video.move( delta * 10 , 0 ) ; }
else if( sf::Keyboard::isKeyPressed( sf::Keyboard::Left ) ) { video.move( - delta * 10 , 0 ) ; }
if( sf::Keyboard::isKeyPressed( sf::Keyboard::Up ) ) { video.move( 0 , - delta * 10 ) ; }
else if( sf::Keyboard::isKeyPressed( sf::Keyboard::Down ) ) { video.move( 0 , delta * 10 ) ; }
window.clear();
window.draw( video ) ; // It's a sf::Drawable too.
window.display();
}
return 0;
}
Hope in this (or the next) week i can release the code on GitHub with a good documentation and test-suite.
Features actually implemented:
-play for local file
-play for url
-get video information (only for local file)
-pause/play/stop/restart
-resize (native way)
-change video playing time.
-set audio channel.
-decrease/increase volume
-set aspect ratio.
-control update rate.