@lls/lls-audio 0.0.3
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/README.md +1244 -0
- package/common/adapter.js +2592 -0
- package/common/waveform.js +181 -0
- package/package.json +50 -0
- package/player/Audio.js +192 -0
- package/player/CustomPlayer.js +218 -0
- package/player/CustomWave.js +158 -0
- package/player/Speed.js +98 -0
- package/player/Wave.js +173 -0
- package/player/index.js +218 -0
- package/player/styles/fallbackTimelineClassNames.js +43 -0
- package/player/styles/sliderDefaultClassNames.js +120 -0
- package/player/styles/styles.js +65 -0
- package/player/styles/timelineClassNames.js +62 -0
- package/player/styles/volumeClassNames.js +44 -0
- package/player/utils.js +53 -0
- package/recorder/AsyncLoader.js +84 -0
- package/recorder/DesktopAudioRecorder.js +165 -0
- package/recorder/DesktopRecorder.js +144 -0
- package/recorder/MobileRecorder.js +46 -0
- package/recorder/index.js +35 -0
- package/stories/customPlayer.js +21 -0
- package/stories/index.js +53 -0
- package/stories/player.js +21 -0
- package/stories/recorder.js +30 -0
- package/utils/audio.js +123 -0
- package/utils/audioContext.js +10 -0
|
@@ -0,0 +1,181 @@
|
|
|
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;
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lls/lls-audio",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"devDependencies": {
|
|
6
|
+
"@kadira/storybook": "^2.21.0",
|
|
7
|
+
"css-loader": "^0.26.1",
|
|
8
|
+
"style-loader": "^0.13.1",
|
|
9
|
+
"babel-preset-es2015": "^6.3.13",
|
|
10
|
+
"babel-preset-react": "^6.3.13",
|
|
11
|
+
"babel-preset-stage-0": "^6.3.13",
|
|
12
|
+
"babel-cli": "^6.9.0",
|
|
13
|
+
"superheroes": "^1.0.0",
|
|
14
|
+
"conventional-changelog": "^1.1.0",
|
|
15
|
+
"conventional-changelog-cli": "^1.2.0",
|
|
16
|
+
"@kadira/storybook-deployer": "^1.0.0",
|
|
17
|
+
"release-it": "^2.4.0"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"aphrodite": "^1.1.0",
|
|
21
|
+
"is_js": "^0.9.0",
|
|
22
|
+
"material-ui": "^0.16.5",
|
|
23
|
+
"merge-audio-buffers": "^1.0.0",
|
|
24
|
+
"msr": "^1.3.4",
|
|
25
|
+
"react-input-range": "^0.9.3",
|
|
26
|
+
"waveform-data": "^2.0.0"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"react": "15.3.1",
|
|
30
|
+
"react-dom": "15.3.1"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=0.12.0"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"url": "github.com/lelivrescolaire/lls-ui"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"start": "npm run storybook",
|
|
40
|
+
"storybook": "start-storybook -p 9009 -s public",
|
|
41
|
+
"deploy-storybook": "storybook-to-ghpages",
|
|
42
|
+
"build": "rm -rf dist && mkdir dist && babel -d dist src",
|
|
43
|
+
"copy:package": "cp -R package.json dist/",
|
|
44
|
+
"copy:readme": "cp -R README.md dist/",
|
|
45
|
+
"npm:publish": "npm run build && npm run release && npm run copy:readme && npm run copy:package && cd dist && npm publish && cd .. && npm run deploy-storybook",
|
|
46
|
+
"release": "npm run changelog && npm run rilize -- --non-interactive",
|
|
47
|
+
"rilize": "$(npm bin)/release-it --github.releaseName=\"%s (`$(npm bin)/superheroes`)\"",
|
|
48
|
+
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s"
|
|
49
|
+
}
|
|
50
|
+
}
|
package/player/Audio.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
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; }; }();
|
|
8
|
+
|
|
9
|
+
var _react = require('react');
|
|
10
|
+
|
|
11
|
+
var _react2 = _interopRequireDefault(_react);
|
|
12
|
+
|
|
13
|
+
var _utils = require('./utils');
|
|
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
|
+
var Player = function (_Component) {
|
|
24
|
+
_inherits(Player, _Component);
|
|
25
|
+
|
|
26
|
+
function Player(props) {
|
|
27
|
+
_classCallCheck(this, Player);
|
|
28
|
+
|
|
29
|
+
var _this = _possibleConstructorReturn(this, (Player.__proto__ || Object.getPrototypeOf(Player)).call(this, props));
|
|
30
|
+
|
|
31
|
+
_this.play = function () {
|
|
32
|
+
return _this.refs.player.play();
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
_this.pause = function () {
|
|
36
|
+
return _this.refs.player.pause();
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
_this.setLoop = function () {
|
|
40
|
+
var loop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
41
|
+
return _this.setStateWithCallback({ loop: loop });
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
_this.setRange = function (currentRange) {
|
|
45
|
+
return _this.setStateWithCallback({ currentRange: currentRange }, _this.onAudioUpdate);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
_this.setSpeed = function () {
|
|
49
|
+
var speed = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
50
|
+
|
|
51
|
+
_this.refs.player.playbackRate = speed;
|
|
52
|
+
_this.setStateWithCallback({ speed: speed });
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
_this.setCurrentTime = function () {
|
|
56
|
+
var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
57
|
+
return _this.refs.player.currentTime = time;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
_this.onAudioUpdate = function () {
|
|
61
|
+
return _this.setStateWithCallback({ currentTime: _this.getCurrentTime() });
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
_this.onPlay = function () {
|
|
65
|
+
return _this.setStateWithCallback({ play: true });
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
_this.onPause = function () {
|
|
69
|
+
return _this.setStateWithCallback({ play: false });
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
_this.onEnded = function () {
|
|
73
|
+
var _this$state = _this.state,
|
|
74
|
+
loop = _this$state.loop,
|
|
75
|
+
startTime = _this$state.currentRange.startTime;
|
|
76
|
+
|
|
77
|
+
_this.setCurrentTime(startTime);
|
|
78
|
+
if (loop) _this.play();
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
_this.state = {
|
|
82
|
+
play: false,
|
|
83
|
+
currentTime: 0,
|
|
84
|
+
volume: 100,
|
|
85
|
+
currentRange: false,
|
|
86
|
+
loop: false,
|
|
87
|
+
speed: 1,
|
|
88
|
+
duration: 0
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
(0, _utils.autoBind)(['onEnded', 'onDurationChange', 'onAudioUpdate', 'onPlay', 'onPause'], _this);
|
|
92
|
+
|
|
93
|
+
// Execute callback onChange props
|
|
94
|
+
_this.setStateWithCallback = function (state) {
|
|
95
|
+
var cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
96
|
+
return _this.setState(state, function () {
|
|
97
|
+
_this.props.onChange(state);
|
|
98
|
+
cb ? cb() : false;
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
return _this;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
_createClass(Player, [{
|
|
105
|
+
key: 'render',
|
|
106
|
+
value: function render() {
|
|
107
|
+
var _props = this.props,
|
|
108
|
+
_props$autoPlay = _props.autoPlay,
|
|
109
|
+
autoPlay = _props$autoPlay === undefined ? false : _props$autoPlay,
|
|
110
|
+
_props$src = _props.src,
|
|
111
|
+
src = _props$src === undefined ? '' : _props$src,
|
|
112
|
+
_props$loop = _props.loop,
|
|
113
|
+
loop = _props$loop === undefined ? false : _props$loop,
|
|
114
|
+
_props$preload = _props.preload,
|
|
115
|
+
preload = _props$preload === undefined ? 'auto' : _props$preload;
|
|
116
|
+
|
|
117
|
+
return _react2.default.createElement('audio', { ref: 'player', autoPlay: autoPlay, src: src, loop: loop, preload: preload });
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Controls
|
|
121
|
+
|
|
122
|
+
}, {
|
|
123
|
+
key: 'setVolume',
|
|
124
|
+
value: function setVolume() {
|
|
125
|
+
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;
|
|
126
|
+
|
|
127
|
+
var volume = Math.min(value, 100);
|
|
128
|
+
this.refs.player.volume = volume / 100;
|
|
129
|
+
this.setStateWithCallback({ volume: volume });
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// HTML5 events
|
|
133
|
+
|
|
134
|
+
}, {
|
|
135
|
+
key: 'componentDidMount',
|
|
136
|
+
value: function componentDidMount() {
|
|
137
|
+
this.props.onChange(this.state);
|
|
138
|
+
|
|
139
|
+
var player = this.refs.player;
|
|
140
|
+
|
|
141
|
+
player.addEventListener('ended', this.onEnded);
|
|
142
|
+
player.addEventListener('durationchange', this.onDurationChange);
|
|
143
|
+
player.addEventListener('timeupdate', this.onAudioUpdate);
|
|
144
|
+
player.addEventListener('play', this.onPlay);
|
|
145
|
+
player.addEventListener('pause', this.onPause);
|
|
146
|
+
}
|
|
147
|
+
}, {
|
|
148
|
+
key: 'componentWillUnmount',
|
|
149
|
+
value: function componentWillUnmount() {
|
|
150
|
+
var player = this.refs.player;
|
|
151
|
+
|
|
152
|
+
player.removeEventListener('ended', this.onEnded);
|
|
153
|
+
player.removeEventListener('durationchange', this.onDurationChange);
|
|
154
|
+
player.removeEventListener('timeupdate', this.onAudioUpdate);
|
|
155
|
+
player.removeEventListener('play', this.onPlay);
|
|
156
|
+
player.removeEventListener('pause', this.onPause);
|
|
157
|
+
}
|
|
158
|
+
}, {
|
|
159
|
+
key: 'getCurrentTime',
|
|
160
|
+
value: function getCurrentTime() {
|
|
161
|
+
var currentTime = this.refs.player.currentTime;
|
|
162
|
+
var _state = this.state,
|
|
163
|
+
_state$currentRange = _state.currentRange,
|
|
164
|
+
startTime = _state$currentRange.startTime,
|
|
165
|
+
endTime = _state$currentRange.endTime,
|
|
166
|
+
loop = _state.loop;
|
|
167
|
+
// check if current time is in the middle of current range
|
|
168
|
+
|
|
169
|
+
if (currentTime > endTime || currentTime < startTime) {
|
|
170
|
+
this.setCurrentTime(startTime);
|
|
171
|
+
if (!loop) this.pause();
|
|
172
|
+
return startTime;
|
|
173
|
+
}
|
|
174
|
+
return currentTime;
|
|
175
|
+
}
|
|
176
|
+
}, {
|
|
177
|
+
key: 'onDurationChange',
|
|
178
|
+
value: function onDurationChange() {
|
|
179
|
+
var duration = this.refs.player.duration;
|
|
180
|
+
|
|
181
|
+
this.setStateWithCallback({
|
|
182
|
+
currentTime: 0,
|
|
183
|
+
duration: duration,
|
|
184
|
+
currentRange: { startTime: 0, endTime: duration }
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}]);
|
|
188
|
+
|
|
189
|
+
return Player;
|
|
190
|
+
}(_react.Component);
|
|
191
|
+
|
|
192
|
+
exports.default = Player;
|
|
@@ -0,0 +1,218 @@
|
|
|
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;
|