Skip to content

Commit fa6965a

Browse files
authored
Merge pull request #48 from voxel51/player51imagesequence
Player51imagesequence
2 parents a1fef07 + 413ba95 commit fa6965a

15 files changed

Lines changed: 774 additions & 198 deletions

src/css/player51.css

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
padding: 5px;
2020
opacity: 0;
2121
z-index: 20;
22-
2322
display: flex;
2423
flex-direction: row;
2524
justify-content: center;
@@ -71,6 +70,12 @@
7170
margin: 3px;
7271
}
7372

73+
.controls-auto-size {
74+
min-height: 30px;
75+
max-height: 70px;
76+
height: 10%;
77+
}
78+
7479

7580
/* Functionality Parts. Do not edit. */
7681
.p51-contained-video, .p51-contained-image, .p51-contained-canvas {
@@ -80,8 +85,8 @@
8085
bottom: 0;
8186
right: 0;
8287
margin: auto;
83-
max-width: 100%;
84-
min-width: 80%;
88+
width: 100%;
89+
max-height: 100%;
8590
}
8691

8792
.p51-contained-canvas {

src/js/galleryviewer.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
MediaPlayer,
1515
} from './mediaplayer.js';
1616

17-
// ES6 module export
1817
export {
1918
GalleryViewer,
2019
};
@@ -39,7 +38,7 @@ GalleryViewer.prototype.constructor = GalleryViewer;
3938

4039

4140
/**
42-
* Set a poster frame URL to display while the video itself is loading
41+
* Set a poster frame URL to display while the gallery itself is loading
4342
*
4443
* @member setLoadingPoster
4544
* @param {string} url Image to be shown while loading.

src/js/imagesequence.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
* @module imagesequence.js
3+
* @summary Defines a client-side media player that can load a zip of images
4+
* and play throught like a video while rendering overlayed metadata.
5+
*
6+
* @desc ImageSequence is a javascript based image player that can take a
7+
* sequence of images and render annotations and markup overlayed on top while
8+
* playing through like a video.
9+
*
10+
* Copyright 2017-2019, Voxel51, Inc.
11+
* Kevin Qi, kevin@voxel51.com
12+
*/
13+
14+
import {
15+
MediaPlayer,
16+
} from './mediaplayer.js';
17+
18+
export {
19+
ImageSequence,
20+
};
21+
22+
23+
/**
24+
* ImageSequence Class Definition
25+
*
26+
* INHERITS: MediaPlayer
27+
* F-MIXINS: None
28+
* @constructor
29+
* @param {object} media is an object that has "src" and "type" attributes.
30+
* type must be in the format imagesequence/<format>
31+
* ex. type: "imagesequence/zip"
32+
* @param {string} overlay is data that should be overlayed on the psuedo video.
33+
* Overlay is a path to a file of eta.core.image.ImageSetLabels format.
34+
* @param {int} fps is the frame-rate of the media.
35+
*/
36+
function ImageSequence(media, overlay, fps) {
37+
MediaPlayer.call(this, 'imagesequence', media, overlay, fps);
38+
}
39+
ImageSequence.prototype = Object.create(MediaPlayer.prototype);
40+
ImageSequence.prototype.constructor = ImageSequence;
41+
42+
43+
/**
44+
* Set a poster frame UR to display while the image sequence is loading
45+
*
46+
* @member setLoadingPoster
47+
* @param {string} url Image to be shown while loading.
48+
*/
49+
ImageSequence.prototype.setLoadingPoster = function(url) {
50+
this._boolHasPoster = true;
51+
this._loadingPosterURL = url;
52+
};
53+
54+
55+
/**
56+
* Loop is not for image sequences.
57+
* Not supported.
58+
*
59+
* @member loop
60+
*/
61+
ImageSequence.prototype.loop = function() {
62+
};
63+
64+
65+
/**
66+
* Autoplay is not for image sequences.
67+
* Not supported.
68+
*
69+
* @member autoplay
70+
*/
71+
ImageSequence.prototype.autoplay = function() {
72+
};
73+
74+
75+
/**
76+
* ResetToFragment is not for image sequences.
77+
* Not supported.
78+
*
79+
* @member resetToFragment
80+
*/
81+
ImageSequence.prototype.resetToFragment = function() {
82+
};
83+
84+
85+
/**
86+
* ThumbnailMode is not for image sequences.
87+
* Not supported.
88+
*
89+
* @member thumbnailMode
90+
* @param {function} action (optional) a callback function to associate with
91+
* any click on an image.
92+
*/
93+
ImageSequence.prototype.thumbnailMode = function(action) {
94+
};

src/js/imageviewer.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
MediaPlayer,
1616
} from './mediaplayer.js';
1717

18-
// ES6 module export
1918
export {
2019
ImageViewer,
2120
};

src/js/mediaplayer.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ import {
2020
import {
2121
GalleryRenderer,
2222
} from './renderers/galleryrenderer.js';
23+
import {
24+
ImageSequenceRenderer,
25+
} from './renderers/imagesequencerenderer.js';
2326

24-
// ES6 module export
2527
export {
2628
MediaPlayer,
2729
};
@@ -51,6 +53,8 @@ function MediaPlayer(type, media, overlay, fps) {
5153
this.renderer = new ImageRenderer(media, overlay);
5254
} else if (type == 'gallery') {
5355
this.renderer = new GalleryRenderer(media, overlay);
56+
} else if (type == 'imagesequence') {
57+
this.renderer = new ImageSequenceRenderer(media, overlay, fps);
5458
} else {
5559
throw new Error('Renderer not initialized.');
5660
}

src/js/overlay.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
*/
1111

1212

13-
// ES6 module export
1413
export {
1514
ColorGenerator,
1615
Overlay,

src/js/player51.js

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* usage is here.
1313
*
1414
* To switch between types of media, specify the type attribute in media
15-
* in the following format.
15+
* in the following format, otherwise known as MIME type.
1616
* <media type>/<media format>
1717
* examples: image/jpg, video/mp4, application/zip
1818
@@ -44,7 +44,7 @@
4444
</script>
4545
4646
```
47-
47+
* For videos and images,
4848
* Note that default behavior is to mirror the size of the enclosing container.
4949
* You can, however, alter this in two ways.
5050
* 1. You can call `player.forceMax()` which will force the video or
@@ -54,10 +54,13 @@
5454
* or image and its enclosing container to the width and height you pass in.
5555
* Both such calls need to be made before the render call.
5656
*
57-
* TODO: implement an abstraction to for the overlay rendering. Currently it
58-
* is directly tied to a canvas. But, one can consider implementing this via
59-
* div/DOM rendering and bringing the full power of CSS to bear on the
60-
* overlays, including animation.
57+
* For zip files,
58+
* Note that the default behaviour is to have each image mirror the size of the
59+
* enclosing container.
60+
*
61+
* Also note that there are two options for rendering zip files,
62+
* Default: render as an image gallery.
63+
* SequenceFlag = true: render as a psuedo videoplayer.
6164
*
6265
* Copyright 2017-2019, Voxel51, Inc.
6366
* Jason Corso, jason@voxel51.com
@@ -76,8 +79,10 @@ import {
7679
import {
7780
GalleryViewer,
7881
} from './galleryviewer.js';
82+
import {
83+
ImageSequence,
84+
} from './imagesequence.js';
7985

80-
// ES6 module export
8186
export default Player51;
8287

8388

@@ -96,17 +101,22 @@ export default Player51;
96101
* In the case of images: Overlay can be a string pointing to a single URL.
97102
* @param {int} fps is the frame-rate of the media. If it is not provided
98103
* then it will be guessed. Ignore in the case of images.
99-
*
104+
* @param {bool} sequenceFlag tells the player to render the zip file as either
105+
* an image gallery or a video player.
100106
*/
101-
function Player51(media, overlay, fps) {
107+
function Player51(media, overlay, fps = 0, sequenceFlag = false) {
102108
this.mediaType = this.determineMediaType(media);
103109
// Load correct player
104110
if (this.mediaType === 'video') {
105111
this.player = new VideoPlayer(media, overlay, fps);
106112
} else if (this.mediaType === 'image') {
107113
this.player = new ImageViewer(media, overlay);
108-
} else if (this.mediaType === 'gallery' || this.mediaType === 'application') {
109-
this.player = new GalleryViewer(media, overlay);
114+
} else if (this.mediaType === 'application' && this.mediaFormat === 'zip') {
115+
if (sequenceFlag) {
116+
this.player = new ImageSequence(media, overlay, fps);
117+
} else {
118+
this.player = new GalleryViewer(media, overlay);
119+
}
110120
} else {
111121
/* eslint-disable-next-line no-console */
112122
console.log('WARN: Player51 doesn\'t support this media type yet.');
@@ -136,6 +146,19 @@ Player51.prototype.setBoolDrawFrameNumber = function(value) {
136146
};
137147

138148

149+
/**
150+
* This function sets player.renderer.reader.workerScriptsPath
151+
*
152+
* @member setZipLibraryParameters
153+
* @param {string} path relative to zip.js
154+
*/
155+
Player51.prototype.setZipLibraryParameters = function(path) {
156+
if (this.player.renderer) {
157+
this.player.renderer.reader.workerScriptsPath = path;
158+
}
159+
};
160+
161+
139162
/**
140163
* This function figures out the type of media to be rendered.
141164
*
@@ -148,6 +171,7 @@ Player51.prototype.determineMediaType = function(media) {
148171
if (splitResults.length !== 2) {
149172
throw new Error('Media type is incorrect.');
150173
}
174+
this.mediaFormat = splitResults[1];
151175
return splitResults[0];
152176
};
153177

0 commit comments

Comments
 (0)