HeapVideo
heapvlcPlays video through libVLC, decoding frames into a dynamic heaps texture shown via `bitmap`.
Backed by native/vlc.c (built into `vlc.hdll` by native/build.ps1), which has to exist before use.
libVLC does its own decoding, so `play()` takes anything it supports (mp4, mkv, webm, etc.)
and also supports URL streaming.
Standalone `h2d.Object` - doesn't depend on any particular host engine's update convention,
just Heaps' own per-frame `sync()`, so `new heapvlc.HeapVideo(parent)` works in any Heaps scene.
Members
- bitmap
- loop
- onEndReached
- onFormatSetup
- onPlaying
- onError
- fitWidth
- fitHeight
- playing
- duration
- position
- time
- volume
- muted
- rate
- audioTrackCount
- audioTrack
- subtitleTrackCount
- subtitleTrack
- new
- load
- play
- getLog
- pause
- resume
- stop
- destroy
Variables
The `h2d.Bitmap` child that displays decoded video frames. Untextured until the first frame arrives.
When true, playback restarts from the beginning instead of stopping at `onEndReached`.
Fires when playback reaches the end of the media - after a loop restart, or after `stop()` on a non-looping end.
Fires once the decoder reports the video's pixel size and `bitmap`'s texture has been (re)created.
Fires when libVLC's "playing" event is observed; see `LibVLC.take_playing`. Can fire again after a pause/resume.
Fires once when the native player reports a playback error; call `getLog()` for details.
When set, `bitmap` is scaled down (never up) to fit within this size and centered on
whichever axes are set, once the native dimensions are known. Set before or after play().
Whether the native player considers itself currently playing. `false` when nothing is loaded.
Media duration in milliseconds, or `0` when nothing is loaded.
Playback position, normalized `0..1`. Writable to seek; `0` when nothing is loaded.
Playback position in milliseconds. Writable to seek; `0` when nothing is loaded.
Volume, `0..100+` (`100` = normal). Defaults to `100` when nothing is loaded.
Whether audio output is muted.
Playback speed multiplier, e.g. `0.5` for half speed, `2.0` for double. `1.0` when nothing is loaded.
Number of available audio tracks, or `0` when nothing is loaded.
Selected audio track id (not necessarily 0-based - see `audioTrackCount`), or `-1` for none.
Number of available subtitle tracks, or `0` when nothing is loaded.
Selected subtitle track id (not necessarily 0-based - see `subtitleTrackCount`), or `-1` for none/disabled.
Functions
function new(?parent:h2d.Object):Void
public function new(?parent:h2d.Object) { super(parent); bitmap = new h2d.Bitmap(this); ensureInit(); }
Creates the player and its `bitmap`, optionally attaching it under `parent`. Runs one-time
libVLC init if needed.
| ?parent | h2d.Object | Optional Heaps object to attach this player under. |
function load(path:String, ?isUrl:Bool):HeapVideo
public function load(path:String, ?isUrl:Bool):HeapVideo { stop(); var url = isUrl != null ? isUrl : urlScheme.match(path); handle = LibVLC.open(toCString(path), url); if (handle == null) throw 'HeapVideo: failed to open "$path"' + errorSuffix(); return this; }
Stops any current playback and opens `path` (a local file path or a streaming URL) for
this player, without starting playback.
| path | String | A local file path or a streaming URL. |
| ?isUrl | Bool | Whether `path` is a URL. Auto-detected from a `scheme://` prefix when omitted. |
function play(?path:String, ?isUrl:Bool):HeapVideo
public function play(?path:String, ?isUrl:Bool):HeapVideo { if (path != null) load(path, isUrl); if (handle == null) throw "HeapVideo: play() called with nothing loaded - call load() or pass a path"; errorSeen = false; // vlc_play() resets the native errored flag along with starting playback if (!LibVLC.play(handle)) throw "HeapVideo: failed to play" + errorSuffix(); return this; }
Starts playback. Pass `path` to `load()` it first, or call after a previous `load()`.
| ?path | String | Optional media to `load()` before playing. |
| ?isUrl | Bool | Forwarded to `load()` when `path` is given. |
function getLog():String
public function getLog():String { var buf = haxe.io.Bytes.alloc(8192); var len = LibVLC.get_log(buf, buf.length); return buf.getString(0, len); }
Recent libVLC diagnostic log (info/warning/error) since this player's last `load()`/
`play()` call - useful when playback silently doesn't progress (wrong URL, unresolved
stream, missing codec, ...) without `open()`/`play()` themselves reporting failure.
function pause():Void
public function pause():Void { if (handle != null) LibVLC.set_pause(handle, true); }
Pauses playback. No-op when nothing is loaded.
function resume():Void
public function resume():Void { if (handle != null) LibVLC.set_pause(handle, false); }
Resumes playback after `pause()`. No-op when nothing is loaded.
function stop():Void
public function stop():Void { if (handle != null) { LibVLC.close(handle); handle = null; } sizeKnown = false; frameWidth = 0; frameHeight = 0; errorSeen = false; }
stops playback and frees the native player. safe to call when nothing's playing.
function destroy():Void
// destroys the object. public function destroy():Void { stop(); remove(); }