OFVideoPlayer
Search:
BigScreens / OFVideoPlayer

openFrameWorks video player

Code: mpeMoviePlayerMaster.zip, mpeMoviePlayerClient.zip

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. Client

The 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 movie

Both 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 broadcasts

The 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 listens

Using 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 file

It'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:

  • window dimensions
  • movie dimensions
  • movie filename
  • movie location in window
  • how often to broadcast the movie position info
  • fullscreen (true or false)
  • movie loops (true or false)
  • IP addresses of clients (hardcoded as just 2 clients)
  • Ports for each client

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

  • the downloads are configured to test locally, the XML files for running on the six screens should look like:
  • LEFT AND RIGHT (CLIENT)

<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>

  • MIDDLE (MASTER)

<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>
Search
  Page last modified on October 20, 2009, at 08:02 PM