Video.hx 879 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. class Video extends hxd.App {
  2. var video : h2d.Video;
  3. var tf : h2d.Text;
  4. override function init() {
  5. tf = new h2d.Text(hxd.res.DefaultFont.get(), s2d);
  6. video = new h2d.Video(s2d);
  7. video.onError = function(e) {
  8. tf.text = e;
  9. tf.textColor = 0xFF0000;
  10. };
  11. function start() {
  12. #if hl
  13. video.load("testVideo.avi");
  14. #elseif js
  15. video.load("testVideo.mp4");
  16. #end
  17. }
  18. video.onEnd = start;
  19. start();
  20. }
  21. override function update(dt:Float) {
  22. if( video.videoWidth != 0 && video.videoHeight != 0 ) {
  23. tf.text = (Std.int(video.time*10)/10)+"s";
  24. var scale = hxd.Math.min(s2d.width / video.videoWidth, s2d.height / video.videoHeight);
  25. video.setScale(scale);
  26. video.x = Std.int((s2d.width - video.videoWidth * scale) * 0.5);
  27. video.y = Std.int((s2d.height - video.videoHeight * scale) * 0.5);
  28. }
  29. }
  30. static function main() {
  31. new Video();
  32. }
  33. }