Skip to content

emscripten: add js File access plugin

Mehdi Sabwat requested to merge b1ue/vlc:emfs.access.1 into master

Emscripten currently does not support picking a file from the DOM with the element, and reading it from a webassembly application.

This access plugin will be able to receive a File object handle in the input thread, and read into buffers in linear memory with the file content while keeping track of the offset.

A basic setup could look like :

<input type="file" id="fpicker_btn">Select File</input>
<script>
let instance = _libvlc_new();
let media_player_ptr = _libvlc_media_player_new(instance);

/*
	Module is the emscripten runtime object,
	it has the vlc_access_file array as a property
*/

let inputElement = document.getElementById("fpicker_btn");

function handleFile() {
	 var name = this.files.item(0).name;
	 console.log("opened file: ", name);
         // id starts at 1
         let id = 1;
	 let path_ptr = Module.allocateUTF8("emjsfile://" + id);
	 let media_ptr = _libvlc_media_new_location(path_ptr);
	 Module._free(path_ptr);
	 _libvlc_media_player_set_media(media_player_ptr, media_ptr);
	 Module['vlc_access_file'][id] = this.files.item(0);
}
inputElement.addEventListener("change", handleFile, false);

_libvlc_media_player_play(media_player_ptr);
</script>
Edited by Mehdi Sabwat

Merge request reports