@lls/lls-audio 0.0.16 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/player/Audio.js +24 -6
- package/player/index.js +30 -7
- package/player/styles/styles.js +14 -1
- package/player/styles/timelineClassNames.js +1 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lls/lls-audio",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"devDependencies": {
|
|
6
6
|
"@kadira/storybook": "^2.21.0",
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
"node": ">=0.12.0"
|
|
35
35
|
},
|
|
36
36
|
"repository": {
|
|
37
|
-
"url": "github.com/lelivrescolaire/
|
|
37
|
+
"url": "github.com/lelivrescolaire/sound-poke"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"start": "npm run storybook",
|
|
41
|
-
"storybook": "start-storybook -p 9009
|
|
41
|
+
"storybook": "start-storybook -p 9009",
|
|
42
42
|
"deploy-storybook": "storybook-to-ghpages",
|
|
43
43
|
"build": "rm -rf dist && mkdir dist && babel -d dist src",
|
|
44
44
|
"copy:package": "cp -R package.json dist/",
|
package/player/Audio.js
CHANGED
|
@@ -28,6 +28,8 @@ var Player = function (_Component) {
|
|
|
28
28
|
|
|
29
29
|
var _this = _possibleConstructorReturn(this, (Player.__proto__ || Object.getPrototypeOf(Player)).call(this, props));
|
|
30
30
|
|
|
31
|
+
_this.requestAnimationId = null;
|
|
32
|
+
|
|
31
33
|
_this.play = function () {
|
|
32
34
|
return _this.refs.player.play();
|
|
33
35
|
};
|
|
@@ -65,12 +67,27 @@ var Player = function (_Component) {
|
|
|
65
67
|
return _this.setStateWithCallback({ currentTime: _this.getCurrentTime() });
|
|
66
68
|
};
|
|
67
69
|
|
|
70
|
+
_this.watchAudioUpdate = function () {
|
|
71
|
+
var step = function step(timestamp) {
|
|
72
|
+
if (_this.getCurrentTime() !== _this.state.currentTime) {
|
|
73
|
+
_this.setStateWithCallback({ currentTime: _this.getCurrentTime() });
|
|
74
|
+
}
|
|
75
|
+
_this.requestAnimationId = requestAnimationFrame(step);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
_this.requestAnimationId = requestAnimationFrame(step);
|
|
79
|
+
};
|
|
80
|
+
|
|
68
81
|
_this.onPlay = function () {
|
|
69
|
-
|
|
82
|
+
_this.setStateWithCallback({ play: true }, function () {
|
|
83
|
+
return _this.watchAudioUpdate();
|
|
84
|
+
});
|
|
70
85
|
};
|
|
71
86
|
|
|
72
87
|
_this.onPause = function () {
|
|
73
|
-
|
|
88
|
+
_this.setStateWithCallback({ play: false }, function () {
|
|
89
|
+
return cancelAnimationFrame(_this.requestAnimationId);
|
|
90
|
+
});
|
|
74
91
|
};
|
|
75
92
|
|
|
76
93
|
_this.onEnded = function () {
|
|
@@ -92,7 +109,7 @@ var Player = function (_Component) {
|
|
|
92
109
|
duration: 0
|
|
93
110
|
};
|
|
94
111
|
|
|
95
|
-
(0, _utils.autoBind)(['onEnded', 'onDurationChange', '
|
|
112
|
+
(0, _utils.autoBind)(['onEnded', 'onDurationChange', 'onPlay', 'onPause', 'onAudioUpdate'], _this);
|
|
96
113
|
|
|
97
114
|
// Execute callback onChange props
|
|
98
115
|
_this.setStateWithCallback = function (state) {
|
|
@@ -139,14 +156,13 @@ var Player = function (_Component) {
|
|
|
139
156
|
key: 'componentDidMount',
|
|
140
157
|
value: function componentDidMount() {
|
|
141
158
|
this.props.onChange(this.state);
|
|
142
|
-
|
|
143
159
|
var player = this.refs.player;
|
|
144
160
|
|
|
145
161
|
player.addEventListener('ended', this.onEnded);
|
|
146
162
|
player.addEventListener('durationchange', this.onDurationChange);
|
|
147
|
-
player.addEventListener('timeupdate', this.onAudioUpdate);
|
|
148
163
|
player.addEventListener('play', this.onPlay);
|
|
149
164
|
player.addEventListener('pause', this.onPause);
|
|
165
|
+
player.addEventListener('timeupdate', this.onAudioUpdate);
|
|
150
166
|
}
|
|
151
167
|
}, {
|
|
152
168
|
key: 'componentWillUnmount',
|
|
@@ -155,9 +171,9 @@ var Player = function (_Component) {
|
|
|
155
171
|
|
|
156
172
|
player.removeEventListener('ended', this.onEnded);
|
|
157
173
|
player.removeEventListener('durationchange', this.onDurationChange);
|
|
158
|
-
player.removeEventListener('timeupdate', this.onAudioUpdate);
|
|
159
174
|
player.removeEventListener('play', this.onPlay);
|
|
160
175
|
player.removeEventListener('pause', this.onPause);
|
|
176
|
+
player.removeEventListener('timeupdate', this.onAudioUpdate);
|
|
161
177
|
}
|
|
162
178
|
}, {
|
|
163
179
|
key: 'getCurrentTime',
|
|
@@ -168,6 +184,7 @@ var Player = function (_Component) {
|
|
|
168
184
|
startTime = _state$currentRange.startTime,
|
|
169
185
|
endTime = _state$currentRange.endTime,
|
|
170
186
|
loop = _state.loop;
|
|
187
|
+
|
|
171
188
|
// check if current time is in the middle of current range
|
|
172
189
|
|
|
173
190
|
if (currentTime > endTime || currentTime < startTime) {
|
|
@@ -183,6 +200,7 @@ var Player = function (_Component) {
|
|
|
183
200
|
var duration = this.refs.player.duration;
|
|
184
201
|
|
|
185
202
|
this.setStateWithCallback({
|
|
203
|
+
play: false,
|
|
186
204
|
currentTime: 0,
|
|
187
205
|
duration: duration,
|
|
188
206
|
currentRange: { startTime: 0, endTime: duration }
|
package/player/index.js
CHANGED
|
@@ -84,7 +84,20 @@ var Player = function (_Component) {
|
|
|
84
84
|
return _this.refs.audio.setRange(range);
|
|
85
85
|
};
|
|
86
86
|
|
|
87
|
-
_this.
|
|
87
|
+
_this.toggleVisible = function () {
|
|
88
|
+
var visible = _this.state.visible;
|
|
89
|
+
|
|
90
|
+
_this.setState({
|
|
91
|
+
visible: !visible
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
_this.state = {
|
|
96
|
+
waveform: false,
|
|
97
|
+
loading: true,
|
|
98
|
+
containerWidth: 0,
|
|
99
|
+
visible: true
|
|
100
|
+
};
|
|
88
101
|
_this.setContainerWidth = (0, _utils.debounce)(_this.setContainerWidth.bind(_this), 500);
|
|
89
102
|
_this.onKeyPress = _this.onKeyPress.bind(_this);
|
|
90
103
|
return _this;
|
|
@@ -109,7 +122,7 @@ var Player = function (_Component) {
|
|
|
109
122
|
}, {
|
|
110
123
|
key: 'componentWillReceiveProps',
|
|
111
124
|
value: function componentWillReceiveProps(newProps) {
|
|
112
|
-
if (newProps.src !== this.props.src) {
|
|
125
|
+
if (newProps.src !== this.props.src || newProps.visible !== newProps.visible) {
|
|
113
126
|
this.initialize(newProps);
|
|
114
127
|
}
|
|
115
128
|
}
|
|
@@ -138,10 +151,16 @@ var Player = function (_Component) {
|
|
|
138
151
|
value: function initialize(props) {
|
|
139
152
|
var _this3 = this;
|
|
140
153
|
|
|
141
|
-
var src = props.src
|
|
154
|
+
var src = props.src,
|
|
155
|
+
_props$visible = props.visible,
|
|
156
|
+
visible = _props$visible === undefined ? true : _props$visible;
|
|
142
157
|
|
|
143
158
|
(0, _audio.getWaveform)(src).then(function (waveform) {
|
|
144
|
-
_this3.setState({
|
|
159
|
+
_this3.setState({
|
|
160
|
+
waveform: waveform,
|
|
161
|
+
loading: false,
|
|
162
|
+
visible: visible
|
|
163
|
+
});
|
|
145
164
|
});
|
|
146
165
|
}
|
|
147
166
|
}, {
|
|
@@ -161,7 +180,8 @@ var Player = function (_Component) {
|
|
|
161
180
|
containerWidth = _state.containerWidth,
|
|
162
181
|
speed = _state.speed,
|
|
163
182
|
_state$currentRange = _state.currentRange,
|
|
164
|
-
currentRange = _state$currentRange === undefined ? {} : _state$currentRange
|
|
183
|
+
currentRange = _state$currentRange === undefined ? {} : _state$currentRange,
|
|
184
|
+
visible = _state.visible;
|
|
165
185
|
var _currentRange$startTi = currentRange.startTime,
|
|
166
186
|
startTime = _currentRange$startTi === undefined ? 0 : _currentRange$startTi,
|
|
167
187
|
_currentRange$endTime = currentRange.endTime,
|
|
@@ -169,7 +189,7 @@ var Player = function (_Component) {
|
|
|
169
189
|
|
|
170
190
|
return _react2.default.createElement(
|
|
171
191
|
'div',
|
|
172
|
-
{ className: 'Audio_player ' + (0, _noImportant.css)(styles.player) + ' ' + className },
|
|
192
|
+
{ className: 'Audio_player ' + (0, _noImportant.css)(styles.player) + ' ' + className + ' ' + (visible ? '' : (0, _noImportant.css)(styles.hidden)) },
|
|
173
193
|
_react2.default.createElement(
|
|
174
194
|
'div',
|
|
175
195
|
{ className: (0, _noImportant.css)(styles.play_and_stop), onClick: function onClick() {
|
|
@@ -213,7 +233,10 @@ var Player = function (_Component) {
|
|
|
213
233
|
_react2.default.createElement(_reactInputRange2.default, { classNames: _volumeClassNames2.default, maxValue: 100, minValue: 0, value: this.state.volume, onChange: function onChange(c, v) {
|
|
214
234
|
return _this4.refs.audio.setVolume(v);
|
|
215
235
|
} })
|
|
216
|
-
)
|
|
236
|
+
),
|
|
237
|
+
_react2.default.createElement('div', { className: 'Close ' + (0, _noImportant.css)(styles.close), onClick: function onClick() {
|
|
238
|
+
return _this4.toggleVisible();
|
|
239
|
+
} })
|
|
217
240
|
);
|
|
218
241
|
}
|
|
219
242
|
}]);
|
package/player/styles/styles.js
CHANGED
|
@@ -60,5 +60,18 @@ exports.default = {
|
|
|
60
60
|
':hover': {
|
|
61
61
|
overflow: 'visible'
|
|
62
62
|
}
|
|
63
|
-
})
|
|
63
|
+
}),
|
|
64
|
+
close: {
|
|
65
|
+
cursor: 'pointer',
|
|
66
|
+
position: 'absolute',
|
|
67
|
+
top: 1,
|
|
68
|
+
right: 3,
|
|
69
|
+
':after': {
|
|
70
|
+
content: "'✖'",
|
|
71
|
+
color: '#e5e5e5'
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
hidden: {
|
|
75
|
+
display: 'none'
|
|
76
|
+
}
|
|
64
77
|
};
|