Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / pas2js / 2019-10

project SaintClaus for pas2js 1.5.1

4 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

warleyalex

live preview: https://pas2js.github.io/master/projectSantaClaus/ download project: https://pas2js.github.io/master/projectSantaClaus.rar

Note:
===
Project written by Ingemar Ragnemalm (2018) using the old pas2js ver 0.8.39 (macOS).
New version: Pas2JS Compiler version 1.5.1 [2019/10/15] for Win64 x86_64

On the previous version, we have the "Uncaught (in promise) DOMException", In modern versions of Chrome, you can’t have videos autoplay with sound enabled by default. We need a button to the user click and that will break if play doesn't return a promise (currently, play() only returns a promise in Chrome, Anyway.

I believe some changes are required in the web.pas unit:

  TJSKeyboardEvent = class external name 'KeyboardEvent' (TJSUIEvent)
  private
    FkeyCode: Integer; external name 'keyCode'; // Read Only
  Public
    property keyCode: Integer read FkeyCode;
  end;
  TJSHTMLImageElement = class external name 'Image' (TJSHTMLElement)
  Public
    constructor New; overload;
  end;
  TJSAudio = class external name 'Audio' (TJSHTMLAudioElement)
  public
    constructor New; overload;
    constructor New(src: String); overload;
    function play: TJSAudio; overload; external name 'play';
  end;

Reply by email

Michael Van Canneyt
to warleyalex
warleyalex wrote 23 lines
live preview: https://pas2js.github.io/master/projectSantaClaus/ download project: https://pas2js.github.io/master/projectSantaClaus.rar Note: === Project written by Ingemar Ragnemalm (2018) using the old pas2js ver 0.8.39 (macOS). New version: Pas2JS Compiler version 1.5.1 [2019/10/15] for Win64 x86_64 On the previous version, we have the "Uncaught (in promise) DOMException", In modern versions of Chrome, you can’t have videos autoplay with sound enabled by default. We need a button to the user click and that will break if play doesn't return a promise (currently, play() only returns a promise in Chrome, Anyway. I believe some changes are required in the web.pas unit: TJSKeyboardEvent = class external name 'KeyboardEvent' (TJSUIEvent) private FkeyCode: Integer; external name 'keyCode'; // Read Only Public property keyCode: Integer read FkeyCode; end;

Deprecated

https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode

Show quoted text 5 lines
TJSHTMLImageElement = class external name 'Image' (TJSHTMLElement) Public constructor New; overload; end;

Not according to

https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/Image

But I added 'overload' so the new of TJSObject is found.

Show quoted text 7 lines
TJSAudio = class external name 'Audio' (TJSHTMLAudioElement) public constructor New; overload; constructor New(src: String); overload; function play: TJSAudio; overload; external name 'play'; end;

I need to check this. The class is not Audio, but HTMLAudioElement.

Michael.

Reply by email

warleyalex
to Michael Van Canneyt
The new changes:
===========
type
  TJSAudio = class external name 'Audio' (TJSHTMLAudioElement)
  public
    constructor New(src: String); overload;
  end;
procedure PlaySound(snd: TJSHTMLAudioElement);
begin
  if snd.paused then
    snd.play()
  else
    snd.currentTime := 0;
end;

{ The audio work for me if I define GetSound method this way. }

function GetSound(fileName: String; loop: Boolean): TJSAudio;
var
  snd: TJSAudio;
begin
  snd := TJSAudio.new(fileName);
  snd.loop := loop;
  GetSound := snd;
  Result := snd;
end;

(...)

  PlaySound( GetSound('assets/jingle_bells.mp3', true) ); // the audio play

for me without errors :)

[quote] The class is not Audio, but HTMLAudioElement. [/quote]

--> if the GetSound method return the TJSHTMLAudioElement instead of TJSAudio, I've got "Illegal constructor" console error, the audio does not play for me :)

Reply by email

Michael Van Canneyt
to warleyalex
warleyalex wrote 13 lines
The new changes: =========== (...) PlaySound( GetSound('assets/jingle_bells.mp3', true) ); // the audio play for me without errors :) [quote] The class is not Audio, but HTMLAudioElement. [/quote] --> if the GetSound method return the TJSHTMLAudioElement instead of TJSAudio, I've got "Illegal constructor" console error, the audio does not play for me :)

I am aware of this, but your solution is wrong. The class name is HTMLAudioElement.

Specially for such occasions, Mattias implemented a new constructor syntax which I need to check & implement.

Michael.

Reply by email