|
BigScreens / OFVideoPlayer
openFrameWorks video playerThe example projects are in DropBox (examples2011/ofvideoplayer) This page outlines the example openFrameWorks video player example. It is not, however, a tutorial in openFrameWorks. For a quick "OF for Processing programmers" guide, visit: http://wiki.openframeworks.cc/index.php?title=OF_for_Processing_users Master vs. ClientThe video player operates on a simple principle. One machine, the "master", just plays the video. The other two machines sit and wait for the master to tell them it is playing and what part of the movie (the movie's "position") to play. Loading and displaying the movieBoth the master and client have to load the movie in setup(): // Load movie file movie.loadMovie(movieFile); movie.play(); Idle the movie in update(): movie.idleMovie(); And display the movie in draw(): movie.draw(movieX,movieY,movieWidth,movieHeight); Master broadcastsThe master grabs the position info from the movie. float p = movie.getPosition(); And every N number of frames, broadcasts the position information using an OSC message.
// Broadcast current position information of movie
if (count % howOften == 0)) {
ofxOscMessage m;
m.setAddress( "/movie/position" );
m.addFloatArg(p);
sender1.sendMessage(m);
sender2.sendMessage(m);
}
You can broadcast the position info every single frame, but this will likely cause the movie to stutter. The client listensUsing OSC, the client checks to see if it has received a message.
// Check for waiting messages
while( receiver.hasWaitingMessages() )
{
// Get the next message
ofxOscMessage m;
receiver.getNextMessage( &m );
// Check for movie position info
if ( strcmp( m.getAddress(), "/movie/position" ) == 0 )
{
float p = m.getArgAsFloat(0);
And once it has that message in a variable, it can set the movie's position:
// Set the position
movie.setPosition(p);
}
}
XML config fileIt's incredibly useful to include configuration information in an XML file that the OF application can read so that you don't have to recompile your application each time you want to change a setting. This example includes the following information in its XML file:
Here's how the XML looks:
<settings>
<client1>
<address>127.0.0.1</address>
<port>12345</port>
</client1>
<client2>
<address>127.0.0.1</address>
<port>12346</port>
</client2>
<movie>fingers.mov</movie>
<howoften>100</howoften>
<dimensions>
<width>500</width>
<height>200</height>
<movieWidth>100</movieWidth>
<movieHeight>100</movieHeight>
<movieX>10</movieX>
<movieY>10</movieY>
</dimensions>
<go_fullscreen>false</go_fullscreen>
<loop>true</loop>
</settings>
And then we use the OF add-on "OFXXMLSETTINGS" to read the XML data. For example:
movieX = xmlReader.getValue("settings:dimensions:movieX", 640, 0);
movieY = xmlReader.getValue("settings:dimensions:movieY", 480, 0);
XML files
<settings>
<port>12345</port>
<movie>yourmoviefile.mov</movie>
<dimensions>
<width>2720</width>
<height>768</height>
<movieWidth>2720</movieWidth>
<movieHeight>768</movieHeight>
<movieX>0</movieX>
<movieY>0</movieY>
</dimensions>
<go_fullscreen>true</go_fullscreen>
<loop>false</loop>
</settings>
<settings>
<client1>
<address>192.168.130.240</address>
<port>12345</port>
</client1>
<client2>
<address>192.168.130.242</address>
<port>12345</port>
</client2>
<movie>yourmoviefile.mov</movie>
<howoften>100</howoften>
<dimensions>
<width>2720</width>
<height>768</height>
<movieWidth>2720</movieWidth>
<movieHeight>768</movieHeight>
<movieX>0</movieX>
<movieY>0</movieY>
</dimensions>
<go_fullscreen>true</go_fullscreen>
<loop>true</loop>
</settings>
|