deanm / plask

Plask is a multimedia programming environment.
www.plask.org
Other
443 stars 38 forks source link

Added duration getter to AVPlayer #33

Open vorg opened 9 years ago

vorg commented 9 years ago

Added duration getter for AVPlayer e.g.:

this.audio = new plask.AVPlayer();
this.audio.appendFile('test.mp3');
this.audio.play();
console.log(this.audio.duration());
deanm commented 9 years ago

The thing about AVPlayer is that it is a playlist. So duration could mean the duration of the entire playlist, just the current item, etc. Maybe currentDuration, and there could also be a totalDuration?

vorg commented 9 years ago

Renaming it to currentDuration in order to match currentTime sounds good. Don't need totalDuration. More useful would be currentTract / totalNumTracks.

deanm commented 9 years ago

It's possible that currentItem is nil, see currentLoadedTimeRanges to how to handle that, you should return NULL.

TextureAVPlayer* player = ExtractPlayerPointer(args.This());
AVPlayerItem* item = [player currentItem];
if (item == nil)
  return args.GetReturnValue().SetNull();