Skip to content

Commit

Permalink
Add VideoLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
fedegratti committed Oct 17, 2021
1 parent cce1d4f commit fa33e70
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v5.15.1
v5.16.0
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ohzi-core",
"version": "5.15.1",
"version": "5.16.0",
"description": "OHZI Core Library",
"module": "build/index.module.js",
"source": "src/index.js",
Expand Down
5 changes: 3 additions & 2 deletions src/resource_loader/AbstractLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default class AbstractLoader

async on_progress(resource_container, response)
{
const response_clone = response.clone();
const reader = response.body.getReader();

// Step 2: get total length
Expand All @@ -89,10 +90,10 @@ export default class AbstractLoader
// console.log(`Received ${receivedLength} of ${contentLength}`);
}

this.on_preloaded_finished(resource_container);
this.on_preloaded_finished(resource_container, response_clone);
}

on_preloaded_finished(resource_container)
on_preloaded_finished(resource_container, response)
{
}

Expand Down
6 changes: 6 additions & 0 deletions src/resource_loader/ResourceBatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import GLTFDRACOLoader from './GLTFDRACOLoader';
import BasisLoader from './BasisLoader';
import ResourceContainer from '../ResourceContainer';
import FileLoader from './FileLoader';
import VideoLoader from './VideoLoader';

export default class ResourceBatch
{
Expand Down Expand Up @@ -73,6 +74,11 @@ export default class ResourceBatch
this.resource_loaders.push(new AudioLoader(resource_id, url, loop, volume, size));
}

add_video(resource_id, url, size)
{
this.resource_loaders.push(new VideoLoader(resource_id, url, size));
}

add_json(resource_id, url, size)
{
this.resource_loaders.push(new JSONLoader(resource_id, url, size));
Expand Down
20 changes: 20 additions & 0 deletions src/resource_loader/VideoLoader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import AbstractLoader from './AbstractLoader';

export default class VideoLoader extends AbstractLoader
{
constructor(resource_id, url, size)
{
super(resource_id, url, size);
}

on_preloaded_finished(resource_container, response)
{
response.blob().then((blob) =>
{
resource_container.set_resource(this.resource_id, this.url, URL.createObjectURL(blob));

this.__update_downloaded_bytes(1, 1);
this.__loading_ended();
});
}
}

0 comments on commit fa33e70

Please sign in to comment.