@lls/lls-audio 0.0.3 → 0.0.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lls/lls-audio",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "main": "index.js",
5
5
  "devDependencies": {
6
6
  "@kadira/storybook": "^2.21.0",
@@ -14,7 +14,9 @@
14
14
  "conventional-changelog": "^1.1.0",
15
15
  "conventional-changelog-cli": "^1.2.0",
16
16
  "@kadira/storybook-deployer": "^1.0.0",
17
- "release-it": "^2.4.0"
17
+ "release-it": "^2.4.0",
18
+ "react": "15.3.1",
19
+ "react-dom": "15.3.1"
18
20
  },
19
21
  "dependencies": {
20
22
  "aphrodite": "^1.1.0",
package/player/index.js CHANGED
@@ -12,9 +12,9 @@ var _react = require('react');
12
12
 
13
13
  var _react2 = _interopRequireDefault(_react);
14
14
 
15
- var _Wave = require('../player/Wave');
15
+ var _CustomWave = require('../player/CustomWave');
16
16
 
17
- var _Wave2 = _interopRequireDefault(_Wave);
17
+ var _CustomWave2 = _interopRequireDefault(_CustomWave);
18
18
 
19
19
  var _audio = require('../utils/audio');
20
20
 
@@ -173,7 +173,7 @@ var Player = function (_Component) {
173
173
  _react2.default.createElement(
174
174
  'div',
175
175
  { className: (0, _noImportant.css)(styles.timeline), ref: 'container' },
176
- _react2.default.createElement(_Wave2.default, { currentTime: currentTime, width: containerWidth, height: 50, range: { startTime: startTime, endTime: endTime }, isLoading: loading, waveform: waveform }),
176
+ _react2.default.createElement(_CustomWave2.default, { currentTime: currentTime, width: containerWidth, height: 50, range: { startTime: startTime, endTime: endTime }, isLoading: loading, waveform: waveform }),
177
177
  _react2.default.createElement(_reactInputRange2.default, { classNames: _fallbackTimelineClassNames2.default, formatLabel: _utils.timeConvert, maxValue: duration || 1, minValue: 0, onChange: function onChange(c, _ref) {
178
178
  var min = _ref.min,
179
179
  max = _ref.max;
@@ -10,9 +10,9 @@ var _react = require('react');
10
10
 
11
11
  var _react2 = _interopRequireDefault(_react);
12
12
 
13
- var _Wave = require('../player/Wave');
13
+ var _CustomWave = require('../player/CustomWave');
14
14
 
15
- var _Wave2 = _interopRequireDefault(_Wave);
15
+ var _CustomWave2 = _interopRequireDefault(_CustomWave);
16
16
 
17
17
  var _audioContext = require('../utils/audioContext');
18
18
 
@@ -95,7 +95,7 @@ var DesktopAudioRecorder = function (_Component) {
95
95
  } },
96
96
  ' record '
97
97
  ),
98
- waveform ? _react2.default.createElement(_Wave2.default, {
98
+ waveform ? _react2.default.createElement(_CustomWave2.default, {
99
99
  width: 500,
100
100
  currentTime: 0,
101
101
  totalTime: 200,
package/stories/index.js CHANGED
@@ -18,10 +18,6 @@ var _player = require('./player');
18
18
 
19
19
  var _player2 = _interopRequireDefault(_player);
20
20
 
21
- var _customPlayer = require('./customPlayer');
22
-
23
- var _customPlayer2 = _interopRequireDefault(_customPlayer);
24
-
25
21
  var _recorder = require('./recorder');
26
22
 
27
23
  var _recorder2 = _interopRequireDefault(_recorder);
@@ -31,18 +27,12 @@ require('../common/material-ui.css');
31
27
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
32
28
 
33
29
  //import PlayerCustom from './playerCustom'
34
- (0, _storybook.storiesOf)('Player', module).add('Soundclound waveform', function () {
30
+ (0, _storybook.storiesOf)('Player', module).add('Custom waveform', function () {
35
31
  return _react2.default.createElement(
36
32
  _MuiThemeProvider2.default,
37
33
  { muiTheme: (0, _getMuiTheme2.default)() },
38
34
  _react2.default.createElement(_player2.default, null)
39
35
  );
40
- }).add('Custom waveform', function () {
41
- return _react2.default.createElement(
42
- _MuiThemeProvider2.default,
43
- { muiTheme: (0, _getMuiTheme2.default)() },
44
- _react2.default.createElement(_customPlayer2.default, null)
45
- );
46
36
  });
47
37
  (0, _storybook.storiesOf)('Recorder', module).add('Normal', function () {
48
38
  return _react2.default.createElement(
@@ -1,181 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- /* This is a custom (temporary version) of http://waveformjs.org/
7
- * because these idiots dont do npms packages.
8
- * I also removed the soundcloud stuff that was useless
9
- */
10
- function Waveform(options) {
11
- this.container = options.container;
12
- this.canvas = options.canvas;
13
- this.data = options.data || [];
14
- this.outerColor = options.outerColor || "transparent";
15
- this.innerColor = options.innerColor || "#000000";
16
- this.interpolate = true;
17
- if (options.interpolate === false) {
18
- this.interpolate = false;
19
- }
20
- if (this.canvas == null) {
21
- if (this.container) {
22
- this.canvas = this.createCanvas(this.container, options.width || this.container.clientWidth, options.height || this.container.clientHeight);
23
- } else {
24
- throw "Either canvas or container option must be passed";
25
- }
26
- }
27
- this.patchCanvasForIE(this.canvas);
28
- this.context = this.canvas.getContext("2d");
29
- this.width = parseInt(this.context.canvas.width, 10);
30
- this.height = parseInt(this.context.canvas.height, 10);
31
- if (options.data) {
32
- this.update(options);
33
- }
34
- }
35
-
36
- Waveform.prototype.setData = function (data) {
37
- return this.data = data;
38
- };
39
-
40
- Waveform.prototype.setDataInterpolated = function (data) {
41
- return this.setData(this.interpolateArray(data, this.width));
42
- };
43
-
44
- Waveform.prototype.setDataCropped = function (data) {
45
- return this.setData(this.expandArray(data, this.width));
46
- };
47
-
48
- Waveform.prototype.update = function (options) {
49
- if (options.interpolate != null) {
50
- this.interpolate = options.interpolate;
51
- }
52
- if (this.interpolate === false) {
53
- this.setDataCropped(options.data);
54
- } else {
55
- this.setDataInterpolated(options.data);
56
- }
57
- return this.redraw();
58
- };
59
-
60
- Waveform.prototype.redraw = function () {
61
- var d, i, middle, t, _i, _len, _ref, _results;
62
- this.clear();
63
- if (typeof this.innerColor === "function") {
64
- this.context.fillStyle = this.innerColor();
65
- } else {
66
- this.context.fillStyle = this.innerColor;
67
- }
68
- middle = this.height / 2;
69
- i = 0;
70
- _ref = this.data;
71
- _results = [];
72
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
73
- d = _ref[_i];
74
- t = this.width / this.data.length;
75
- if (typeof this.innerColor === "function") {
76
- this.context.fillStyle = this.innerColor(i / this.width, d);
77
- }
78
- this.context.clearRect(t * i, middle - middle * d, t, middle * d * 2);
79
- this.context.fillRect(t * i, middle - middle * d, t, middle * d * 2);
80
- _results.push(i++);
81
- }
82
- return _results;
83
- };
84
-
85
- Waveform.prototype.clear = function () {
86
- this.context.fillStyle = this.outerColor;
87
- this.context.clearRect(0, 0, this.width, this.height);
88
- return this.context.fillRect(0, 0, this.width, this.height);
89
- };
90
-
91
- Waveform.prototype.patchCanvasForIE = function (canvas) {
92
- var oldGetContext;
93
- if (typeof window.G_vmlCanvasManager !== "undefined") {
94
- canvas = window.G_vmlCanvasManager.initElement(canvas);
95
- oldGetContext = canvas.getContext;
96
- return canvas.getContext = function (a) {
97
- var ctx;
98
- ctx = oldGetContext.apply(canvas, arguments);
99
- canvas.getContext = oldGetContext;
100
- return ctx;
101
- };
102
- }
103
- };
104
-
105
- Waveform.prototype.createCanvas = function (container, width, height) {
106
- var canvas;
107
- canvas = document.createElement("canvas");
108
- container.appendChild(canvas);
109
- canvas.width = width;
110
- canvas.height = height;
111
- return canvas;
112
- };
113
-
114
- Waveform.prototype.expandArray = function (data, limit, defaultValue) {
115
- var i, newData, _i, _ref;
116
- if (defaultValue == null) {
117
- defaultValue = 0.0;
118
- }
119
- newData = [];
120
- if (data.length > limit) {
121
- newData = data.slice(data.length - limit, data.length);
122
- } else {
123
- for (i = _i = 0, _ref = limit - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
124
- newData[i] = data[i] || defaultValue;
125
- }
126
- }
127
- return newData;
128
- };
129
-
130
- Waveform.prototype.linearInterpolate = function (before, after, atPoint) {
131
- return before + (after - before) * atPoint;
132
- };
133
-
134
- Waveform.prototype.interpolateArray = function (data, fitCount) {
135
- var after, atPoint, before, i, newData, springFactor, tmp;
136
- newData = new Array();
137
- springFactor = new Number((data.length - 1) / (fitCount - 1));
138
- newData[0] = data[0];
139
- i = 1;
140
- while (i < fitCount - 1) {
141
- tmp = i * springFactor;
142
- before = new Number(Math.floor(tmp)).toFixed();
143
- after = new Number(Math.ceil(tmp)).toFixed();
144
- atPoint = tmp - before;
145
- newData[i] = this.linearInterpolate(data[before], data[after], atPoint);
146
- i++;
147
- }
148
- newData[fitCount - 1] = data[data.length - 1];
149
- return newData;
150
- };
151
-
152
- Waveform.prototype.optionsForSyncedStream = function (options) {
153
- var innerColorWasSet, that;
154
- if (options == null) {
155
- options = {};
156
- }
157
- innerColorWasSet = false;
158
- that = this;
159
- return {
160
- whileplaying: this.redraw,
161
- whileloading: function whileloading() {
162
- var stream;
163
- if (!innerColorWasSet) {
164
- stream = this;
165
- that.innerColor = function (x, y) {
166
- if (x < stream.position / stream.durationEstimate) {
167
- return options.playedColor || "rgba(255, 102, 0, 0.8)";
168
- } else if (x < stream.bytesLoaded / stream.bytesTotal) {
169
- return options.loadedColor || "rgba(0, 0, 0, 0.8)";
170
- } else {
171
- return options.defaultColor || "rgba(0, 0, 0, 0.4)";
172
- }
173
- };
174
- innerColorWasSet = true;
175
- }
176
- return this.redraw;
177
- }
178
- };
179
- };
180
-
181
- exports.default = Waveform;
@@ -1,218 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
8
-
9
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
10
-
11
- var _react = require('react');
12
-
13
- var _react2 = _interopRequireDefault(_react);
14
-
15
- var _CustomWave = require('../player/CustomWave');
16
-
17
- var _CustomWave2 = _interopRequireDefault(_CustomWave);
18
-
19
- var _audio = require('../utils/audio');
20
-
21
- var _FontIcon = require('material-ui/FontIcon');
22
-
23
- var _FontIcon2 = _interopRequireDefault(_FontIcon);
24
-
25
- var _noImportant = require('aphrodite/no-important');
26
-
27
- var _reactInputRange = require('react-input-range');
28
-
29
- var _reactInputRange2 = _interopRequireDefault(_reactInputRange);
30
-
31
- var _utils = require('./utils');
32
-
33
- var _volumeClassNames = require('./styles/volumeClassNames');
34
-
35
- var _volumeClassNames2 = _interopRequireDefault(_volumeClassNames);
36
-
37
- var _timelineClassNames = require('./styles/timelineClassNames');
38
-
39
- var _timelineClassNames2 = _interopRequireDefault(_timelineClassNames);
40
-
41
- var _fallbackTimelineClassNames = require('./styles/fallbackTimelineClassNames');
42
-
43
- var _fallbackTimelineClassNames2 = _interopRequireDefault(_fallbackTimelineClassNames);
44
-
45
- var _styles = require('./styles/styles');
46
-
47
- var _styles2 = _interopRequireDefault(_styles);
48
-
49
- var _Audio = require('./Audio');
50
-
51
- var _Audio2 = _interopRequireDefault(_Audio);
52
-
53
- var _Speed = require('./Speed');
54
-
55
- var _Speed2 = _interopRequireDefault(_Speed);
56
-
57
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
58
-
59
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
60
-
61
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
62
-
63
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
64
-
65
- var styles = _noImportant.StyleSheet.create(_styles2.default);
66
-
67
- var Player = function (_Component) {
68
- _inherits(Player, _Component);
69
-
70
- function Player() {
71
- _classCallCheck(this, Player);
72
-
73
- var _this = _possibleConstructorReturn(this, (Player.__proto__ || Object.getPrototypeOf(Player)).call(this));
74
-
75
- _this.state = { waveform: false, loading: true, containerWidth: 0 };
76
- _this.setContainerWidth = (0, _utils.debounce)(_this.setContainerWidth.bind(_this), 500);
77
- _this.onKeyPress = _this.onKeyPress.bind(_this);
78
- return _this;
79
- }
80
-
81
- _createClass(Player, [{
82
- key: 'componentWillMount',
83
- value: function componentWillMount() {
84
- this.initialize(this.props);
85
- }
86
- }, {
87
- key: 'componentDidMount',
88
- value: function componentDidMount() {
89
- var _this2 = this;
90
-
91
- setTimeout(function () {
92
- return _this2.setContainerWidth();
93
- }, 0);
94
- window.addEventListener('resize', this.setContainerWidth);
95
- document.addEventListener('keydown', this.onKeyPress, false);
96
- }
97
- }, {
98
- key: 'componentWillReceiveProps',
99
- value: function componentWillReceiveProps(newProps) {
100
- if (newProps.url !== this.props.url) {
101
- this.initialize(newProps);
102
- }
103
- }
104
- }, {
105
- key: 'componentWillUnmount',
106
- value: function componentWillUnmount() {
107
- window.removeEventListener('resize', this.setContainerWidth);
108
- document.removeEventListener('keydown', this.onKeyPress, false);
109
- }
110
- }, {
111
- key: 'setContainerWidth',
112
- value: function setContainerWidth() {
113
- var container = this.refs.container;
114
-
115
- var containerWidth = container.offsetWidth - 60;
116
- this.setState({ containerWidth: containerWidth });
117
- }
118
- }, {
119
- key: 'onKeyPress',
120
- value: function onKeyPress(e) {
121
- var key = e.keyCode || e.which;
122
- if (key === 32) this.state.play ? this.refs.audio.pause() : this.refs.audio.play();
123
- }
124
- }, {
125
- key: 'initialize',
126
- value: function initialize(props) {
127
- var _this3 = this;
128
-
129
- var url = props.url;
130
-
131
- (0, _audio.getWaveform)(url).then(function (waveform) {
132
- _this3.setState({ waveform: waveform, loading: false });
133
- });
134
- }
135
- }, {
136
- key: 'render',
137
- value: function render() {
138
- var _this4 = this;
139
-
140
- var url = this.props.url;
141
- var _state = this.state,
142
- loading = _state.loading,
143
- duration = _state.duration,
144
- waveform = _state.waveform,
145
- play = _state.play,
146
- currentTime = _state.currentTime,
147
- containerWidth = _state.containerWidth,
148
- speed = _state.speed,
149
- _state$currentRange = _state.currentRange,
150
- currentRange = _state$currentRange === undefined ? {} : _state$currentRange;
151
- var _currentRange$startTi = currentRange.startTime,
152
- startTime = _currentRange$startTi === undefined ? 0 : _currentRange$startTi,
153
- _currentRange$endTime = currentRange.endTime,
154
- endTime = _currentRange$endTime === undefined ? 0 : _currentRange$endTime;
155
-
156
- return _react2.default.createElement(
157
- 'div',
158
- { className: (0, _noImportant.css)(styles.player) },
159
- _react2.default.createElement(
160
- 'div',
161
- { className: (0, _noImportant.css)(styles.play_and_stop), onClick: function onClick() {
162
- return play ? _this4.refs.audio.pause() : _this4.refs.audio.play();
163
- } },
164
- _react2.default.createElement(
165
- _FontIcon2.default,
166
- { className: 'material-icons' },
167
- play ? 'pause' : 'play_arrow'
168
- )
169
- ),
170
- _react2.default.createElement(_Audio2.default, { onChange: function onChange(state) {
171
- return _this4.setState(_extends({}, state));
172
- }, ref: 'audio', src: url }),
173
- _react2.default.createElement(
174
- 'div',
175
- { className: (0, _noImportant.css)(styles.timeline), ref: 'container' },
176
- _react2.default.createElement(_CustomWave2.default, { currentTime: currentTime, width: containerWidth, height: 50, range: { startTime: startTime, endTime: endTime }, isLoading: loading, waveform: waveform }),
177
- _react2.default.createElement(_reactInputRange2.default, { classNames: _fallbackTimelineClassNames2.default, formatLabel: _utils.timeConvert, maxValue: duration || 1, minValue: 0, onChange: function onChange(c, _ref) {
178
- var min = _ref.min,
179
- max = _ref.max;
180
- return _this4.refs.audio.setRange({ startTime: min, endTime: max });
181
- }, value: { min: startTime, max: endTime } }),
182
- _react2.default.createElement(_reactInputRange2.default, { classNames: _timelineClassNames2.default, formatLabel: _utils.timeConvert, maxValue: duration || 1, minValue: 0, value: this.state.currentTime, onChange: function onChange(c, v) {
183
- return _this4.refs.audio.setCurrentTime(v);
184
- } })
185
- ),
186
- _react2.default.createElement(
187
- 'div',
188
- { onClick: function onClick() {
189
- return _this4.refs.audio.setLoop(!_this4.state.loop);
190
- }, className: 'Repeat_menu ' + (0, _noImportant.css)(styles.repeat_menu) },
191
- _react2.default.createElement(
192
- _FontIcon2.default,
193
- { style: { color: this.state.loop ? '#a20025' : '' }, className: 'material-icons' },
194
- 'loop'
195
- )
196
- ),
197
- _react2.default.createElement(
198
- 'div',
199
- { className: 'Speed_menu ' + (0, _noImportant.css)(styles.speed_menu) },
200
- _react2.default.createElement(_Speed2.default, { speed: speed, onSpeedChange: function onSpeedChange(speed) {
201
- return _this4.refs.audio.setSpeed(speed);
202
- } })
203
- ),
204
- _react2.default.createElement(
205
- 'div',
206
- { className: 'Volume ' + (0, _noImportant.css)(styles.volume) },
207
- _react2.default.createElement(_reactInputRange2.default, { classNames: _volumeClassNames2.default, maxValue: 100, minValue: 0, value: this.state.volume, onChange: function onChange(c, v) {
208
- return _this4.refs.audio.setVolume(v);
209
- } })
210
- )
211
- );
212
- }
213
- }]);
214
-
215
- return Player;
216
- }(_react.Component);
217
-
218
- exports.default = Player;
package/player/Wave.js DELETED
@@ -1,173 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- var _react = require('react');
8
-
9
- var _react2 = _interopRequireDefault(_react);
10
-
11
- var _waveform = require('../common/waveform');
12
-
13
- var _waveform2 = _interopRequireDefault(_waveform);
14
-
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
-
17
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
18
-
19
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
20
-
21
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
22
-
23
- // soundcloud waveform
24
-
25
- var RESOLUTION = 1;
26
- var colorScheme = ['#888', '#e51400'];
27
-
28
- var interpolateHeight = function interpolateHeight(totalHeight) {
29
- var amplitude = 256;
30
- return function (size) {
31
- return totalHeight - (size + 128) * totalHeight / amplitude;
32
- };
33
- };
34
-
35
- var chunks = function chunks(arr, chunkSize) {
36
- return arr.map(function (e, i) {
37
- return i % chunkSize === 0 ? arr.slice(i, i + chunkSize) : null;
38
- }).filter(function (e) {
39
- return e;
40
- });
41
- };
42
-
43
- var Wave = function (_Component) {
44
- _inherits(Wave, _Component);
45
-
46
- function Wave(props) {
47
- _classCallCheck(this, Wave);
48
-
49
- //this.loopIsEnabled = false
50
- var _this = _possibleConstructorReturn(this, (Wave.__proto__ || Object.getPrototypeOf(Wave)).call(this, props));
51
-
52
- _initialiseProps.call(_this);
53
-
54
- _this.ctx = null;
55
- _this.soundWave = null;
56
- return _this;
57
- }
58
-
59
- /*
60
- drawLevels = (props) => {
61
- const { height, totalTime, waveform, range, currentTime } = props
62
- const { pixels_per_second } = waveform
63
- const maxWidth = this.refs.canvas.width
64
- const maxHeight = this.refs.canvas.height
65
- // Duration and step calculation
66
- const maxDuration = totalTime || waveform.duration
67
- const levelStep = maxWidth / maxDuration
68
- // Range positions
69
- //@todo: this range stuff should not be here. Waveform should just be passed an array of colors and ranges
70
- const startX = range ? range.startTime / maxDuration * maxWidth : 0
71
- const endX = range ? range.endTime / maxDuration * maxWidth : maxDuration
72
- // Split data into chunks per level
73
- const maxLevelChunks = chunks(waveform.max, Math.floor(pixels_per_second))
74
- // Calculate average for each level + highest average
75
- const { highestAverage, averages } = maxLevelChunks.reduce((memo, levelData) => {
76
- const average = levelData.reduce((memo, data) => memo + data, 0 ) / levelData.length
77
- if(average > memo.highestAverage) {
78
- memo.highestAverage = average
79
- }
80
- memo.averages.push(average)
81
- return memo
82
- }, {highestAverage: 0, averages: []})
83
- // Clear canvas and draw one bar for each level
84
- this.ctx.clearRect(0, 0, maxWidth, maxHeight)
85
- averages.forEach((average, i) => {
86
- const x = i * levelStep
87
- const h = average * (maxHeight / highestAverage )
88
- const color = x >= startX && x <= endX
89
- ? colorScheme[1]
90
- : colorScheme[0]
91
- this.drawLevel({
92
- x: x,
93
- y: maxHeight - h,
94
- w: 1,
95
- h: h,
96
- color: color
97
- })
98
- })
99
- }
100
- drawLevel = (level) => {
101
- this.ctx.fillStyle = `${level.color}`
102
- this.ctx.fillRect(level.x, level.y, level.w, level.h)
103
- }*/
104
-
105
- return Wave;
106
- }(_react.Component);
107
-
108
- var _initialiseProps = function _initialiseProps() {
109
- var _this2 = this;
110
-
111
- this.componentDidMount = function () {
112
- var waveform = _this2.props.waveform;
113
-
114
- _this2.initialise(_this2.props);
115
- };
116
-
117
- this.componentWillReceiveProps = function (nextProps) {
118
- _this2.initialise(nextProps);
119
- };
120
-
121
- this.initialise = function (props) {
122
- var width = props.width,
123
- height = props.height,
124
- waveform = props.waveform,
125
- totalTime = props.totalTime;
126
-
127
- if (!waveform) return;
128
- _this2.drawLevels(props);
129
- };
130
-
131
- this.drawLevels = function (props) {
132
- var waveFormData = props.waveform,
133
- range = props.range;
134
-
135
- var startX = 0; //range ? range.startTime / maxDuration * maxWidth : 0
136
- var endX = 0; //range ? range.endTime / maxDuration * maxWidth : maxDuration
137
-
138
- var maxValue = waveFormData.max.reduce(function (memo, val) {
139
- if (val > memo) memo = val;
140
- return memo;
141
- }, 0);
142
-
143
- var values = waveFormData.max.map(function (val) {
144
- return val === 0 ? 0.01 : val / maxValue;
145
- });
146
-
147
- window.setTimeout(function () {
148
- if (!_this2.soundWave) {
149
- _this2.soundWave = new _waveform2.default({
150
- container: document.getElementById('wave'),
151
- data: values,
152
- innerColor: function innerColor(x, y) {
153
- return x >= startX && x <= endX ? colorScheme[1] : colorScheme[0];
154
- }
155
- });
156
- } else {
157
- _this2.soundWave.update({
158
- data: values
159
- });
160
- }
161
- }, 0); // yeah, sorry
162
- };
163
-
164
- this.render = function () {
165
- return _react2.default.createElement('div', {
166
- id: 'wave',
167
- ref: 'wave',
168
- className: '' + _this2.props.className,
169
- style: { width: _this2.props.width, height: _this2.props.height, position: 'relative', top: 9 } });
170
- };
171
- };
172
-
173
- exports.default = Wave;
@@ -1,21 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- var _react = require('react');
8
-
9
- var _react2 = _interopRequireDefault(_react);
10
-
11
- var _CustomPlayer = require('../player/CustomPlayer');
12
-
13
- var _CustomPlayer2 = _interopRequireDefault(_CustomPlayer);
14
-
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
-
17
- var CustomPlayerExample = function CustomPlayerExample() {
18
- return _react2.default.createElement(_CustomPlayer2.default, { url: 'cranberries_zombie.mp3' });
19
- };
20
-
21
- exports.default = CustomPlayerExample;