Explorar el Código

Added .currentFrame and .currentTime; close #42

Dominic Szablewski hace 10 años
padre
commit
88fa157782
Se han modificado 1 ficheros con 9 adiciones y 1 borrados
  1. 9 1
      jsmpg.js

+ 9 - 1
jsmpg.js Ver fichero

268
 // Loading via Ajax
268
 // Loading via Ajax
269
 
269
 
270
 jsmpeg.prototype.intraFrames = [];
270
 jsmpeg.prototype.intraFrames = [];
271
+jsmpeg.prototype.currentFrame = -1;
272
+jsmpeg.prototype.currentTime = 0;
271
 jsmpeg.prototype.frameCount = 0;
273
 jsmpeg.prototype.frameCount = 0;
272
 jsmpeg.prototype.duration = 0;
274
 jsmpeg.prototype.duration = 0;
273
 	
275
 	
368
 	}
370
 	}
369
 
371
 
370
 	this.buffer.index = target.index;
372
 	this.buffer.index = target.index;
373
+	this.currentFrame = target.frame-1;
371
 
374
 
372
 	// If we're seeking to the exact frame, we may have to decode some more frames before
375
 	// If we're seeking to the exact frame, we may have to decode some more frames before
373
 	// the one we want
376
 	// the one we want
374
 	if( seekExact ) {
377
 	if( seekExact ) {
375
-		for( var currentFrame = target.frame; currentFrame < seekFrame-1; currentFrame++ ) {
378
+		for( var frame = target.frame; frame < seekFrame-1; frame++ ) {
376
 			this.decodePicture(DECODE_SKIP_OUTPUT);
379
 			this.decodePicture(DECODE_SKIP_OUTPUT);
377
 			this.findStartCode(START_PICTURE);
380
 			this.findStartCode(START_PICTURE);
378
 		}
381
 		}
382
+		this.currentFrame = seekFrame-1;
379
 	}
383
 	}
380
 
384
 
381
 	// Decode and display the picture we have seeked to
385
 	// Decode and display the picture we have seeked to
399
 };
403
 };
400
 
404
 
401
 jsmpeg.prototype.stop = function(file) {
405
 jsmpeg.prototype.stop = function(file) {
406
+	this.currentFrame = -1;
402
 	if( this.buffer ) {
407
 	if( this.buffer ) {
403
 		this.buffer.index = this.firstSequenceHeader;
408
 		this.buffer.index = this.firstSequenceHeader;
404
 	}
409
 	}
636
 
641
 
637
 
642
 
638
 jsmpeg.prototype.decodePicture = function(skipOutput) {
643
 jsmpeg.prototype.decodePicture = function(skipOutput) {
644
+	this.currentFrame++;
645
+	this.currentTime = this.currentFrame / this.pictureRate;
646
+
639
 	this.buffer.advance(10); // skip temporalReference
647
 	this.buffer.advance(10); // skip temporalReference
640
 	this.pictureCodingType = this.buffer.getBits(3);
648
 	this.pictureCodingType = this.buffer.getBits(3);
641
 	this.buffer.advance(16); // skip vbv_delay
649
 	this.buffer.advance(16); // skip vbv_delay