Simple Demo
This page shows a copyable local demo layout.
1. Example Directory
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.js2. Start Any Static Web Server
The demo only needs a normal static web server.
python3 -m http.server 80803. index.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
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.
6. Recommended Flow
- Build the player.
- Bind the minimum callbacks.
- Load media.
- Let
auto_playhandle startup, or callplay()afteron_ready_show_done_callback.
7. WebRTC Publish And Playback Demo
Publish an H.264 + AAC stream to ZLMediaKit:
ffmpeg -hide_banner -stream_loop -1 -re \
-i /path/to/input.flv \
-vf scale=640:360,format=yuv420p \
-c:v libx264 -preset veryfast -tune zerolatency \
-profile:v baseline -level 3.1 -bf 0 \
-g 25 -keyint_min 25 -sc_threshold 0 \
-c:a aac -profile:a aac_low -ar 44100 -ac 2 -b:a 128k \
-f flv rtmp://127.0.0.1/live/testUse the standard WHEP playback endpoint with the same player lifecycle:
const rtcPlayer = H265webjsPlayer();
rtcPlayer.on_ready_show_done_callback = function () {
rtcPlayer.play();
};
rtcPlayer.on_play_time = function (seconds) {
console.log('WebRTC play time', seconds);
};
rtcPlayer.on_error_callback = function (error) {
console.error('WebRTC playback error', error);
};
rtcPlayer.build({
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,
auto_play: false,
ignore_audio: false
});
rtcPlayer.load_media('http://127.0.0.1/index/api/whep?app=live&stream=test');Omitting core lets the URL choose WebRTC automatically. Add core: 'webrtc' only when the caller explicitly wants to force WebRTC. Configure ZLMediaKit with modify_stamp=1 as described in Get Started before judging playback smoothness.
The repository also includes a browser WHIP publisher (webrtc-publish.html) and a WHEP player (webrtc-play.html). WHIP is for publishing; WHEP is for playback.