@@ -86,7 +86,7 @@ public class Movie extends PImage implements PConstants {
86
86
protected int [] copyPixels = null ;
87
87
88
88
protected boolean firstFrame = true ;
89
- protected boolean seeking = false ;
89
+ // protected boolean seeking = false;
90
90
91
91
protected boolean useBufferSink = false ;
92
92
protected boolean outdatedPixels = true ;
@@ -172,13 +172,36 @@ protected void finalize() throws Throwable {
172
172
* @brief Sets the target frame rate
173
173
*/
174
174
public void frameRate (float ifps ) {
175
- if (seeking ) return ;
175
+ // if (seeking) return;
176
176
177
177
// We calculate the target ratio in the case both the
178
178
// current and target framerates are valid (greater than
179
179
// zero), otherwise we leave it as 1.
180
180
float f = (0 < ifps && 0 < frameRate ) ? ifps / frameRate : 1 ;
181
-
181
+
182
+ long t = playbin .queryPosition (TimeUnit .NANOSECONDS );
183
+ long start , stop ;
184
+ if (rate > 0 ) {
185
+ start = t ;
186
+ stop = -1 ;
187
+ } else {
188
+ start = 0 ;
189
+ stop = t ;
190
+ }
191
+
192
+ Gst .invokeLater (new Runnable () {
193
+ public void run () {
194
+ boolean res = playbin .seek (rate * f , Format .TIME , EnumSet .of (SeekFlags .FLUSH , SeekFlags .ACCURATE ), SeekType .SET , start , SeekType .SET , stop );
195
+ if (!res ) {
196
+ PGraphics .showWarning ("Seek operation failed." );
197
+ }
198
+ }
199
+ });
200
+
201
+ frameRate = ifps ;
202
+
203
+
204
+ /*
182
205
if (playing) {
183
206
playbin.pause();
184
207
playbin.getState();
@@ -211,6 +234,7 @@ public void frameRate(float ifps) {
211
234
}
212
235
213
236
frameRate = ifps;
237
+ */
214
238
}
215
239
216
240
@@ -291,7 +315,7 @@ public float time() {
291
315
* @brief Jumps to a specific location
292
316
*/
293
317
public void jump (float where ) {
294
- if (seeking ) return ;
318
+ // if (seeking) return;
295
319
296
320
if (!sinkReady ) {
297
321
initSink ();
@@ -304,54 +328,16 @@ public void jump(float where) {
304
328
where = frame / nativeFrameRate ;
305
329
}
306
330
307
- boolean res ;
308
331
long pos = Video .secToNanoLong (where );
309
332
310
- res = playbin .seek (rate , Format .TIME , EnumSet .of (SeekFlags .FLUSH , SeekFlags .ACCURATE ), SeekType .SET , pos , SeekType .NONE , -1 );
311
-
312
- if (!res ) {
313
- PGraphics .showWarning ("Seek operation failed." );
314
- }
315
-
316
- // getState() will wait until any async state change
317
- // (like seek in this case) has completed
318
- seeking = true ;
319
- playbin .getState ();
320
- seeking = false ;
321
- /*
322
- if (seeking) return; // don't seek again until the current seek operation is done.
323
-
324
- if (!sinkReady) {
325
- initSink();
326
- }
327
-
328
- // Round the time to a multiple of the source framerate, in
329
- // order to eliminate stutter. Suggested by Daniel Shiffman
330
- float fps = getSourceFrameRate();
331
- int frame = (int)(where * fps);
332
- final float seconds = frame / fps;
333
-
334
- // Put the seek operation inside a thread to avoid blocking the main
335
- // animation thread
336
- Thread seeker = new Thread() {
337
- @Override
333
+ Gst .invokeLater (new Runnable () {
338
334
public void run () {
339
- long pos = Video.secToNanoLong(seconds);
340
- boolean res = playbin.seek(rate, Format.TIME, SeekFlags.FLUSH,
341
- SeekType.SET, pos, SeekType.NONE, -1);
335
+ boolean res = playbin .seek (rate , Format .TIME , EnumSet .of (SeekFlags .FLUSH , SeekFlags .ACCURATE ), SeekType .SET , pos , SeekType .NONE , -1 );
342
336
if (!res ) {
343
337
PGraphics .showWarning ("Seek operation failed." );
344
- }
345
-
346
- // getState() will wait until any async state change
347
- // (like seek in this case) has completed
348
- seeking = true;
349
- playbin.getState();
350
- seeking = false;
338
+ }
351
339
}
352
- };
353
- seeker.start();
354
- */
340
+ });
355
341
}
356
342
357
343
@@ -383,7 +369,7 @@ public boolean available() {
383
369
* @brief Plays movie one time and stops at the last frame
384
370
*/
385
371
public void play () {
386
- if (seeking ) return ;
372
+ // if (seeking) return;
387
373
388
374
if (!sinkReady ) {
389
375
initSink ();
@@ -408,7 +394,7 @@ public void play() {
408
394
* @brief Plays a movie continuously, restarting it when it's over.
409
395
*/
410
396
public void loop () {
411
- if (seeking ) return ;
397
+ // if (seeking) return;
412
398
413
399
repeat = true ;
414
400
play ();
@@ -428,7 +414,7 @@ public void loop() {
428
414
* @brief Stops the movie from looping
429
415
*/
430
416
public void noLoop () {
431
- if (seeking ) return ;
417
+ // if (seeking) return;
432
418
433
419
if (!sinkReady ) {
434
420
initSink ();
@@ -451,7 +437,7 @@ public void noLoop() {
451
437
* @brief Pauses the movie
452
438
*/
453
439
public void pause () {
454
- if (seeking ) return ;
440
+ // if (seeking) return;
455
441
456
442
if (!sinkReady ) {
457
443
initSink ();
@@ -477,7 +463,7 @@ public void pause() {
477
463
* @brief Stops the movie
478
464
*/
479
465
public void stop () {
480
- if (seeking ) return ;
466
+ // if (seeking) return;
481
467
482
468
if (!sinkReady ) {
483
469
initSink ();
0 commit comments