Skip to content

Simple Demo

This page shows a copyable local demo layout.

1. Example Directory

text
root/
├── index.html
├── index.js
├── resource/
│   └── hevc_test_moov_set_head_16s.mp4
└── output/
    ├── h265web.js
    ├── h265web_wasm.js
    ├── h265web_wasm.wasm
    ├── extjs.js
    └── extwasm.js

2. Start Any Static Web Server

The demo only needs a normal static web server.

bash
python3 -m http.server 8080

3. index.html

html
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>h265web.js PRO Demo</title>
    <script src="./output/h265web.js"></script>
  </head>
  <body>
    <div id="canvas111"></div>

    <div class="control-container">
      <button id="play_btn" onclick="play()" disabled>PLAY</button>
      <button id="pause_btn" onclick="pause()" disabled>PAUSE</button>
      <button id="voice_btn" onclick="setVoice()" disabled>VOLUME</button>
    </div>

    <div class="mode-container">
      <button onclick="buildPlayer('webcodec_hevc')">WEBCODEC</button>
      <button onclick="buildPlayer('wasm_hevc')">SIMD</button>
      <button onclick="buildPlayer('mse_hevc')">MSE</button>
      <button onclick="buildPlayer()">AUTO</button>
    </div>

    <script src="./index.js"></script>
  </body>
</html>

4. index.js

js
let ylplayer = null;
const mediaUrl = './resource/hevc_test_moov_set_head_16s.mp4';

function createPlayer(core = null) {
  if (ylplayer) {
    ylplayer.release();
    ylplayer = null;
  }

  ylplayer = H265webjsPlayer();

  ylplayer.on_ready_show_done_callback = function () {
    document.getElementById('play_btn').disabled = false;
    document.getElementById('pause_btn').disabled = false;
    document.getElementById('voice_btn').disabled = false;
  };

  ylplayer.video_probe_callback = function (mediaInfo) {
    console.log('mediaInfo', mediaInfo);
  };

  ylplayer.on_play_time = function (pts) {
    console.log('play pts', pts);
  };

  const playerConfig = {
    player_id: 'canvas111',
    base_url: './output/',
    wasm_js_uri: 'h265web_wasm.js',
    wasm_wasm_uri: 'h265web_wasm.wasm',
    ext_src_js_uri: 'extjs.js',
    ext_wasm_js_uri: 'extwasm.js',
    width: '100%',
    height: 480,
    color: '#101318',
    auto_play: true,
    readframe_multi_times: -1,
    ignore_audio: false
  };

  if (core) {
    playerConfig.core = core;
  }

  ylplayer.build(playerConfig);
}

function buildPlayer(core = null) {
  createPlayer(core);
  ylplayer.load_media(mediaUrl);
}

function play() {
  ylplayer && ylplayer.play();
}

function pause() {
  ylplayer && ylplayer.pause();
}

function setVoice() {
  ylplayer && ylplayer.set_voice(1.0);
}

window.onload = function () {
  buildPlayer();
};

5. Path Notes

The current SDK accepts these path styles for both SDK resources and media URLs:

  • Full URL: https://example.com/output/h265web_wasm.js
  • Site-absolute path: /output/h265web_wasm.js
  • Relative path: ./output/h265web_wasm.js

If you use base_url, the four SDK resource files can stay as short file names.

  1. Build the player.
  2. Bind the minimum callbacks.
  3. Load media.
  4. Let auto_play handle startup, or call play() after on_ready_show_done_callback.