We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I have a problem with videos launches : I want to play a succession of clips, of 20-30s , in two Movies instances
all together.
clip A1 clip B1
clip A2 ""
"" clip B2
etc...
When a new clip begins with play(), B2 by exemple, then A2 which is not finished freezes. I tried with a timer and I saw that in the case where I had to launch the play() the duration of draw() was 200ms vs 4-5ms without play().
I read some discussions with my problem and the only answer is to write the play() in the setup(). But it's not the way I have to use because my project is to play with many clips (more than 500) automatically during
several hours. It's look like to me this is impossible to launch so many clips in the programm start.
Is there a possibility to prepare the new clip to be played without slowing down the draw duration? in a different buffer? something like if (myMovie.available()) {myMovie.play()} does not work... Or is this impossible to work simultaneously with two clips with processing?
I join my sketch with two Movies instances : on the top the clip A serie and clip B serie bottom the two clips series succeed one another with alpha. Please I hope you understand my english.
import processing.video.*;
int nbVideo,numVideo;
boolean choixA,transit;
float mAlpha=0;
Movie movA,movB,movActif;
void setup() {
size(1040, 860,JAVA2D);
noSmooth();
background(0);
nbVideo=6;
numVideo=int(random(1, 6));
movA=new Movie(this, numVideo+".avi");
choixA=false;
transition();
charge();
}
void movieEvent(Movie m) {
m.read();
redraw();
}
void charge() {
int m = millis();
numVideo =int (random(1, 6));
if (choixA==true){
movA=new Movie(this, numVideo+".avi");
}
else{
movB=new Movie(this, numVideo+".avi");
}
choixA =!choixA;
int m2 = millis();
println(m2-m+" =charge");
}
void transition(){
int m = millis();
if (choixA==true){
movB.play();
}
else{
movA.play();
}
int m2 = millis();
println(m2-m +" =trans");
}
void draw() {
int m = millis();
tint (255,100);
image(movA, 0, 0 );
image(movB, 500, 0 );
if (choixA==true){
movActif=movA;
}
else{
movActif=movB;
}
tint (255,100-mAlpha);
image(movA,0,400);
tint (255,mAlpha);
image(movB, 0, 400 );
if (movActif.time()>=movActif.duration()-5) {
if (!transit){
transition();
transit=!transit;
}
if (choixA==true){
mAlpha+=1;
}
else{
mAlpha-=1;
}
if ((mAlpha==100)||(mAlpha==0)){
charge();
transit=!transit;
}
}
int m2 = millis();
if (m2-m>40) {println(m2-m +" draw");}
}
Answers
Don't try to format code with quote! See How to format code and text
Ended up coding my own solution based on "Movie Player" @ http://forum.processing.org/two/discussion/7852/problem-with-toggling-between-multiple-videos-on-processing-2-2-1.
However, it's not been tested yet and might be bugged. Hoping you check it out for yourself: ^#(^
Thank you for your help, but sorry, it didn't work. It stopped after the two first clips, there's no preload and I'm not able to understand ...
It seems that :
m.playbin.connect(finishing);
would make run the :
final PlayBin2.ABOUT_TO_FINISH finishing = new PlayBin2.ABOUT_TO_FINISH() { @ Override void aboutToFinish(PlayBin2 elt) { // what's "@ Override"? println("Finishing...", elt.get("uri")); //nothing to read on the board... preloadRandomClip(int(elt.get("name").toString())); } };
when the active 1 (or 2) is about to finish.
As I don't understand the syntax in the
Movie preloadRandomClip(int idx) { return loads[idx] == null ? loads[idx] = loadRandomClip(idx) : loads[idx]; // "?" ?? }
I can't know if there are the instructions in the " preload" which must be modified or a problem in the "aboutToFinish".
@chrjos, finally I've taken the time to grab some 5 small cat videos from YouTube and placed in the "/data/" folder to check my sketch out! #:-S
And then found out what was wrong:
clips[idx].playbin.isPlaying()
was forevertrue
! @-)I've ingenuously assumed once a Movie had finished, its isPlaying() would return
false
! =;Class Movie got lotsa
boolean
fields, including playing, paused, repeat. However they're allprotected
and we can't access them! And by incomprehensible negligence, there ain't any accessor methods provided for them! X(At least field playbin was made
public
, allowing us to access Movie's internal "gstreamer" library!However, I had to peruse that behemoth complicated library in order to learn how to control the Movie!
All of that b/c Movie developers provided such a poor API for us! ~X(
PlayBin2.ABOUT_TO_FINISH was 1 of the complicated things I've found out. This time it's Bus.EOS.
Bus.EOS is called back when the stream is finished playing. So now we can change Movie to another 1! \m/
If you want to, you can learn more about "gstreamer-java" too: O:-)
https://gstreamer-java.googlecode.com/svn/trunk/javadoc/1.5/index.html
And w/o further ado, Preloaded Clips 2: :bz
It's a standard Java Annotation interface:
After some thought, I've come to realize that PlayBin2.ABOUT_TO_FINISH w/ its aboutToFinish() method isn't necessary anymore after we've got Bus.EOS and its endOfStream() method! :@)
So I've refactored version 2 in order to get a more refined & compact version 3: :-bd