SwingOSC – Java-based cross-platform replacements for Cocoa GUI classes

This class is meant as an emulation of SCMovieView. last mod: 04-feb-07 sciss

no-op / not working

editing and selections not possible

loop mode only on / off possible

rate backwards playing seems to be not possible

different behaviour

??? ???

extended functionality

skipFrames additional method

frame_ implemented, but only coarsly working

fixedAspectRatio _ to display always with correct aspect ratio

known issues / todo

frame getting not yet working, setting only coarsely working

aesthetics default controller looks extremely ugly, makes you want to puke

resizeWithMagnif seems to be including controller height even when controller not visible, to be fixed

JSCMovieView

Note: please use the abstraction layer GUI.movieView if possible! (see [GUI])

superclass: JSCView

// NOTE : INCOMPLETE

can play movies such as .mov and mpg,

and image files like jpg, png, tiff and others.

Prerequisites

JSCMovieView is currently based on the Java Media Framework (JMF) which is not part of the standard java environment (Java SE) but needs to be installed separately. There is a reference implementation from Sun available for Linux, Windows and Mac OS X. It can be downloaded from http://java.sun.com/products/java-media/jmf/index.jsp (note: for Mac OS X you need the generic cross-platform version).

The reference implementation has rather poor media support (check this page: http://java.sun.com/products/java-media/jmf/2.1.1/formats.html ), so you might need to convert your movies or look out for extra JMF plug-ins. A really good plug-in is fobs4j !(ffpmeg objects for java) -> http://fobs.sourceforge.net/ !

You need to install the "jmf.jar" file in your system's java extensions folder, e.g. on Mac OS X that's "/Library/Java/Extensions". For fobs, do the same with "fobs4jmf.jar" and copy "jmf.properties" into "SwingOSC/build".

(in the future, FMJ (freedom for media in java) might be an alternative: http://fmj-sf.net)

Examples

(

w = JSCWindow( "Movie View", Rect( 200, 200, 368, 292 ));

b = JSCButton( w, Rect( 4, 4, 100, 20 ))

.states_([[ "Pick A File" ]])

.canFocus_( false )

.action_({ SwingDialog.getPaths({ arg paths; m.path_( paths.first ); }, nil, 1 )});

m = JSCMovieView( w, Rect( 4, 28, 360, 260 ))

.resize_( 5 );

w.front;

)

// enforce display with original aspect ratio (SwingOSC only)

m.fixedAspectRatio = true;

m.background = Color.blue;

// resize the component to the video's original size

m.resize = 1; // resizeWithMagnification is incompatible with resize !!

m.resizeWithMagnification( 1.0 );

m.resizeWithMagnification( 0.5 ); // half of the original size

m.resizeWithMagnification( 2.0 ); // twice the original size

// random-pick a tiff from the Help folder ; JMF and FOBS : TIFF not supported!

// images don't play properly with FOBS (transport cannot be stopped any more).

// as a workaround paste a jpeg in a quicktime movie

//m.path_( "Help/*/*/*.tiff".pathMatch.choose.absolutePath ); // .absolutePath !

m.path_( "~/*/*.png".standardizePath.pathMatch.choose.absolutePath ); // .absolutePath !

m.path_( "~/*/*/*.mov".standardizePath.pathMatch.choose.absolutePath ); // .absolutePath !

// or point it to a movie (you may have that one too):

m.path_( "/Library/Application\ Support/iDVD/Tutorial/Movies/Our\ First\ Snowman.mov" );

m.start; // playback

m.muted_( true ); // thank god

m.stop;

// rate (1.0 = normal speed, 0.5 = half speed, 2.0 = double speed etc.)

m.rate_( 0.2 );

m.rate_( 1.0 );

// backwards

// NEGATIVE RATES DO NOT SEEM TO WORK WITH THE JMF PLAYER

m.gotoEnd.rate_( -1 ).start;

m.gotoEnd;

// select a range on the controller and play it

// NOT WORKING IN SWINGOSC

//m.rate_(1).playSelectionOnly_(true).start;

// loopModes:

m.loopMode = 1; // only one direction

m.loopMode = 0; // no looping

// NOT WORKING IN SWINGOSC

// m.loopMode_(0).start; // back and forth

m.stop;

m.gotoBeginning;

// single (frame) steps

m.stepForward;

10.do { m.stepForward; }; // hell slow in JMF --> better use skip( 10 )!

m.stepBack;

// select with shift-drag, copy paste between movieviews or quicktime player

// NOT WORKING IN SWINGOSC

//m.editable_(true);

// note: the second argument seems to be irrelevant, for now leave to true always!

m.showControllerAndAdjustSize( false, true );

m.showControllerAndAdjustSize( true, true );

// goto time (in seconds)

m.currentTime_( 1 );

m.currentTime_( 60 );

// not there yet, but would be nice to have:

// startFrame, length

// NOT WORKING IN SWINGOSC

//m.setSelection_(20, 15);

m.frame_( 660 ); // jump to frame (note: only approximate with fobs4j)

// NOT NET WORKING IN SWINGOSC

//m.frame.postln; // poll current frame pos

// advance some frames (SwingOSC only)

m.skipFrames( 100 ); // advance by 10 frames

m.skipFrames( -100 ); // go back 10 frames

More Examples

// try fullscreen (press Escape to leave)

(

w = JSCWindow( "Movie", JSCWindow.screenBounds, false, false );

m = JSCMovieView( w, w.view.bounds )

.showControllerAndAdjustSize( false, false )

.loopMode_( 1 )

.path_( "~/Desktop/test.mov".standardizePath ) // use your own path here

.keyDownAction_({ arg but, char; char.postln; if( char == 27.asAscii, { w.close })})

.background_( Color.black )

.start;

w.front.fullScreen;

m.focus;

)