Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

45
LINES

< > BotCompany Repo | #1032543 // WaveSurfer - wavesurfer.js (graphical HTML audio player) as JavaX classs

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (5138L/29K).

1  
sclass WaveSurfer {
2  
  S randomID = randomIDForPageElement();
3  
  S id = "wavesurfer-" + randomID; // id of container element
4  
  S containerSelector;
5  
  S varName = "waveSurfer_" + randomID; // name of variable for wavesurfer instance
6  
  new MapSO options;
7  
  S audioURL;
8  
  
9  
  S headStuff() {
10  
    ret hscript("https://unpkg.com/wavesurfer.js");
11  
  }
12  
  
13  
  S container() {
14  
    ret emptydiv(+id);
15  
  }
16  
  
17  
  S js_init() {
18  
    if (empty(containerSelector)) containerSelector = "#" + id;
19  
    options.put(container := containerSelector);
20  
    
21  
    ret jsDollarVars([[
22  
      var $waveSurfer = WaveSurfer.create($options);
23  
    ]], +options, waveSurfer := JS(varName));
24  
  }
25  
  
26  
  S js_loadAudio(S url) {
27  
    ret jsDollarVars([[
28  
      $waveSurfer.load($url);
29  
    ]], +url, waveSurfer := JS(varName));
30  
  }
31  
  
32  
  S completeHTML(S audioURL) {
33  
    ret linesLL(
34  
      headStuff(),
35  
      container(),
36  
      hjs(linesLL(js_init(), js_loadAudio(audioURL)))
37  
    );
38  
  }
39  
  
40  
  S js_playPause() {
41  
    ret jsDollarVars([[
42  
      $waveSurfer.playPause();
43  
    ]], waveSurfer := JS(varName));
44  
  }
45  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1032543
Snippet name: WaveSurfer - wavesurfer.js (graphical HTML audio player) as JavaX classs
Eternal ID of this version: #1032543/10
Text MD5: 3f0c3ebd16d9036176d4e73fc0ace1de
Transpilation MD5: a800b8340dcf822fa09f6fb89c125eff
Author: stefan
Category: javax / html
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-09-22 15:36:59
Source code size: 1101 bytes / 45 lines
Pitched / IR pitched: No / No
Views / Downloads: 161 / 317
Version history: 9 change(s)
Referenced in: [show references]