Section 2: Display the Movie Model in DXMCanvas
This class extends the DXMCanvas class. The model you set in this class,
by calling the setModel() method, is the model that will be displayed. |
class DxmMovie extends DXMCanvas {
DxmMovie() {
_model = new VCRModel();
setModel(_model);
}
VCRModel _model;
}
This class extends the Model class. The createModel method in this class
is where you construct your model. |
class VCRModel extends Model {
Import a movie in the model and have a switcher behavior to control
the playback rate. |
public void createModel(BvrsToRun bvrs) {
Create a movie behavior by importing an avi file. |
URL movieBase = buildURL(getImportBase(), "Movie/");
ImageBvr[] imgArr = {null};
SoundBvr[] sndArr = {null};
NumberBvr lenNum = importMovie(buildURL(movieBase, "movie.avi"),
imgArr, sndArr);
The playback rate switcher starts with 1, the normal rate. |
_rateSw = new ModifiableBehavior(toBvr(1));
The playback position of the movie is the sum of the rate. Use
modulus to loop the movie since positions less than 0 or greater than
the length of the movie yields emptyImage. The specialMod is a
private function that always returns a positive number less than
lenNum. |
NumberBvr posNum = specialMod(integral((NumberBvr)_rateSw.getBvr()), lenNum);
Use AppTriggeredEvent for the restart event. When the restart button
is pressed, the event will be triggered. Construct a recursive
position behavior - the resetablePosNum - that resets to itself when
the event occurs. Note that integral has implicit time. When a
restart posNum at the time _resetEv occurs, integration starts from
0. |
_resetEv = new AppTriggeredEvent();
NumberBvr resetablePosNum = NumberBvr.newUninitBvr();
resetablePosNum.init(until(posNum, _resetEv, resetablePosNum));
Play the movie on top of a black background. Use substituteTime
to control the position of a movie. The localTime for movies
is implicit. |
setImage(overlay((ImageBvr)imgArr[0].substituteTime(resetablePosNum),
solidColorImage(black)));
setSound((SoundBvr)sndArr[0].loop().substituteTime(resetablePosNum));
}
This function does a "special" mod for negative numbers. It returns
the linear distance between the passed-in numerator and the biggest
multiple of the denominator smaller than the numerator.
For example, specialMode(-1, 5) = 4, specialMod(-4, 5) = 1.
This is defined so that a decreasing number behavior passed in as the
numerator yields a consistent result whether its value is positive or
negative. |
NumberBvr specialMod(NumberBvr numNum, NumberBvr denomNum) {
return (NumberBvr)cond(gt(numNum, toBvr(0)),
mod(numNum, denomNum),
sub(denomNum, mod(abs(numNum), denomNum)));
}
This method changes the value of the rate switcher to the given rate.
This is called by the event handlers of the playback controls. |
void setRate(int rate) {
_rateSw.switchTo(toBvr(rate*0.1));
}
This method is called when the restart button is pressed. It resets
the rate to the normal playback rate, and triggers the event to
restart the movie. |
void restart() {
setRate(10);
_resetEv.trigger();
}
AppTriggeredEvent _resetEv;
ModifiableBehavior _rateSw;
}
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.