Skip to content
Snippets Groups Projects
Commit 9d2f5d61 authored by Mehdi Sabwat's avatar Mehdi Sabwat Committed by Hugo Beauzée-Luyssen
Browse files

emscripten: add js File access plugin

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>
```
parent 992d7b3f
No related branches found
No related tags found
1 merge request!2149emscripten: add js File access plugin
Pipeline #249600 passed with stage
in 15 minutes and 18 seconds
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment