@ldelia/react-media 0.4.1 → 0.4.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/dist/components/__tests__/timeline/timeline.test.js +5 -10
- package/dist/components/index.js +2 -17
- package/dist/components/timeline/RangeSelectorCanvas/RangeSelectorCanvas.js +16 -44
- package/dist/components/timeline/Timeline.js +26 -56
- package/dist/components/timeline/TimelineCanvas/TickTime.js +5 -10
- package/dist/components/timeline/TimelineCanvas/TickTimeCollectionDisplay.js +9 -14
- package/dist/components/timeline/TimelineCanvas/TimelineCanvas.js +16 -44
- package/dist/components/timeline/TimelineCanvas/drawTimeBlocksOnCanvas.js +4 -8
- package/dist/components/timeline/TimelineValue/TimelineValue.js +24 -54
- package/dist/components/timeline/ZoomContext/ZoomContext.js +2 -8
- package/dist/components/timeline/constants.js +1 -4
- package/dist/components/timeline/index.js +1 -17
- package/dist/components/timeline/utils/utils.js +6 -15
- package/dist/index.js +1 -17
- package/dist/setupTests.js +1 -3
- package/dist/stories/timeline.stories.js +18 -24
- package/package.json +45 -35
- package/.bitmap +0 -48
- package/.eslintcache +0 -1
- package/.prettierignore +0 -3
- package/.prettierrc +0 -7
- package/.storybook/main.js +0 -38
- package/.storybook/preview.js +0 -4
- package/config/env.js +0 -104
- package/config/getHttpsConfig.js +0 -66
- package/config/jest/babelTransform.js +0 -29
- package/config/jest/cssTransform.js +0 -14
- package/config/jest/fileTransform.js +0 -40
- package/config/modules.js +0 -134
- package/config/paths.js +0 -77
- package/config/webpack/persistentCache/createEnvironmentHash.js +0 -9
- package/config/webpack.config.js +0 -755
- package/config/webpackDevServer.config.js +0 -127
- package/dist/components/__tests__/timeline/timeline.test.d.ts +0 -1
- package/dist/components/index.d.ts +0 -1
- package/dist/components/timeline/RangeSelectorCanvas/RangeSelectorCanvas.d.ts +0 -8
- package/dist/components/timeline/Timeline.d.ts +0 -12
- package/dist/components/timeline/TimelineCanvas/TickTime.d.ts +0 -7
- package/dist/components/timeline/TimelineCanvas/TickTimeCollectionDisplay.d.ts +0 -6
- package/dist/components/timeline/TimelineCanvas/TimelineCanvas.d.ts +0 -7
- package/dist/components/timeline/TimelineCanvas/drawTimeBlocksOnCanvas.d.ts +0 -2
- package/dist/components/timeline/TimelineValue/TimelineValue.d.ts +0 -7
- package/dist/components/timeline/ZoomContext/ZoomContext.d.ts +0 -7
- package/dist/components/timeline/constants.d.ts +0 -1
- package/dist/components/timeline/index.d.ts +0 -1
- package/dist/components/timeline/utils/utils.d.ts +0 -7
- package/dist/index.d.ts +0 -1
- package/dist/setupTests.d.ts +0 -1
- package/dist/stories/timeline.stories.d.ts +0 -9
- package/scripts/build.js +0 -217
- package/scripts/start.js +0 -154
- package/scripts/test.js +0 -52
- package/src/components/__tests__/timeline/timeline.test.js +0 -22
- package/src/components/__tests__/timeline/timeline.test.tsx +0 -26
- package/src/components/index.js +0 -2
- package/src/components/index.ts +0 -2
- package/src/components/reproduction-widget/README.md +0 -27
- package/src/components/reproduction-widget/ReproductionWidget.tsx +0 -68
- package/src/components/reproduction-widget/index.tsx +0 -1
- package/src/components/reproduction-widget/inner-players/PlayAlongInnerPlayer.tsx +0 -10
- package/src/components/reproduction-widget/inner-players/YouTubeInnerPlayer.tsx +0 -36
- package/src/components/reproduction-widget/models/Player/PlayAlongPlayer.ts +0 -129
- package/src/components/reproduction-widget/models/Player/PlayerEvents.ts +0 -4
- package/src/components/reproduction-widget/models/Player/YouTubePlayer.ts +0 -171
- package/src/components/reproduction-widget/models/Reproduction.ts +0 -272
- package/src/components/reproduction-widget/models/ReproductionBuilder.ts +0 -70
- package/src/components/timeline/README.md +0 -111
- package/src/components/timeline/RangeSelectorCanvas/RangeSelectorCanvas.js +0 -127
- package/src/components/timeline/RangeSelectorCanvas/RangeSelectorCanvas.tsx +0 -166
- package/src/components/timeline/Timeline.js +0 -77
- package/src/components/timeline/Timeline.tsx +0 -139
- package/src/components/timeline/TimelineCanvas/TickTime.js +0 -26
- package/src/components/timeline/TimelineCanvas/TickTime.tsx +0 -45
- package/src/components/timeline/TimelineCanvas/TickTimeCollectionDisplay.js +0 -19
- package/src/components/timeline/TimelineCanvas/TickTimeCollectionDisplay.tsx +0 -42
- package/src/components/timeline/TimelineCanvas/TimelineCanvas.js +0 -44
- package/src/components/timeline/TimelineCanvas/TimelineCanvas.tsx +0 -79
- package/src/components/timeline/TimelineCanvas/drawTimeBlocksOnCanvas.js +0 -28
- package/src/components/timeline/TimelineCanvas/drawTimeBlocksOnCanvas.ts +0 -43
- package/src/components/timeline/TimelineValue/TimelineValue.js +0 -50
- package/src/components/timeline/TimelineValue/TimelineValue.tsx +0 -87
- package/src/components/timeline/ZoomContext/ZoomContext.js +0 -2
- package/src/components/timeline/ZoomContext/ZoomContext.ts +0 -10
- package/src/components/timeline/constants.js +0 -13
- package/src/components/timeline/constants.ts +0 -13
- package/src/components/timeline/index.js +0 -1
- package/src/components/timeline/index.tsx +0 -1
- package/src/components/timeline/utils/utils.js +0 -28
- package/src/components/timeline/utils/utils.ts +0 -49
- package/src/index.js +0 -1
- package/src/index.ts +0 -1
- package/src/modules.d.ts +0 -1
- package/src/react-app-env.d.ts +0 -71
- package/src/react-docgen-types.d.ts +0 -37
- package/src/setupTests.js +0 -5
- package/src/setupTests.ts +0 -5
- package/src/stories/Configure.mdx +0 -364
- package/src/stories/reproduction-widget.stories.tsx +0 -23
- package/src/stories/timeline.stories.custom.css +0 -29
- package/src/stories/timeline.stories.js +0 -54
- package/src/stories/timeline.stories.tsx +0 -66
- package/storybook-static/favicon.svg +0 -1
- package/storybook-static/index.html +0 -173
- package/storybook-static/index.json +0 -1
- package/storybook-static/nunito-sans-bold-italic.woff2 +0 -0
- package/storybook-static/nunito-sans-bold.woff2 +0 -0
- package/storybook-static/nunito-sans-italic.woff2 +0 -0
- package/storybook-static/nunito-sans-regular.woff2 +0 -0
- package/storybook-static/project.json +0 -1
- package/storybook-static/sb-addons/essentials-actions-3/manager-bundle.js +0 -3
- package/storybook-static/sb-addons/essentials-actions-3/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/essentials-backgrounds-4/manager-bundle.js +0 -12
- package/storybook-static/sb-addons/essentials-backgrounds-4/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/essentials-controls-2/manager-bundle.js +0 -412
- package/storybook-static/sb-addons/essentials-controls-2/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/essentials-measure-7/manager-bundle.js +0 -3
- package/storybook-static/sb-addons/essentials-measure-7/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/essentials-outline-8/manager-bundle.js +0 -3
- package/storybook-static/sb-addons/essentials-outline-8/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/essentials-toolbars-6/manager-bundle.js +0 -3
- package/storybook-static/sb-addons/essentials-toolbars-6/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/essentials-viewport-5/manager-bundle.js +0 -3
- package/storybook-static/sb-addons/essentials-viewport-5/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/links-1/manager-bundle.js +0 -3
- package/storybook-static/sb-addons/links-1/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/storybook-core-core-server-presets-0/common-manager-bundle.js +0 -3
- package/storybook-static/sb-addons/storybook-core-core-server-presets-0/common-manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-common-assets/favicon.svg +0 -1
- package/storybook-static/sb-common-assets/nunito-sans-bold-italic.woff2 +0 -0
- package/storybook-static/sb-common-assets/nunito-sans-bold.woff2 +0 -0
- package/storybook-static/sb-common-assets/nunito-sans-italic.woff2 +0 -0
- package/storybook-static/sb-common-assets/nunito-sans-regular.woff2 +0 -0
- package/storybook-static/sb-manager/globals-module-info.js +0 -995
- package/storybook-static/sb-manager/globals-runtime.js +0 -53527
- package/storybook-static/sb-manager/globals.js +0 -48
- package/storybook-static/sb-manager/runtime.js +0 -11885
- package/storybook-static/sb-preview/globals.js +0 -33
- package/storybook-static/sb-preview/runtime.js +0 -9483
- package/tsconfig.json +0 -14
- /package/{src → dist}/components/reproduction-widget/ReproductionWidget.js +0 -0
- /package/{src → dist}/components/reproduction-widget/index.js +0 -0
- /package/{src → dist}/components/reproduction-widget/inner-players/PlayAlongInnerPlayer.js +0 -0
- /package/{src → dist}/components/reproduction-widget/inner-players/YouTubeInnerPlayer.js +0 -0
- /package/{src → dist}/components/reproduction-widget/models/Player/PlayAlongPlayer.js +0 -0
- /package/{src → dist}/components/reproduction-widget/models/Player/PlayerEvents.js +0 -0
- /package/{src → dist}/components/reproduction-widget/models/Player/YouTubePlayer.js +0 -0
- /package/{src → dist}/components/reproduction-widget/models/Reproduction.js +0 -0
- /package/{src → dist}/components/reproduction-widget/models/ReproductionBuilder.js +0 -0
- /package/{src → dist}/stories/reproduction-widget.stories.js +0 -0
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { createRoot } from 'react-dom/client';
|
|
3
|
-
import { Timeline } from '../../timeline';
|
|
4
|
-
describe('Timeline', () => {
|
|
5
|
-
let props;
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
props = {
|
|
8
|
-
duration: 300,
|
|
9
|
-
value: 15,
|
|
10
|
-
onChange: jest.fn(),
|
|
11
|
-
onRangeChange: jest.fn(),
|
|
12
|
-
zoomLevel: 0,
|
|
13
|
-
};
|
|
14
|
-
});
|
|
15
|
-
describe('render()', () => {
|
|
16
|
-
it('renders a timeline', () => {
|
|
17
|
-
const rootElement = document.createElement('div');
|
|
18
|
-
const root = createRoot(rootElement);
|
|
19
|
-
root.render(React.createElement(Timeline, Object.assign({}, props)));
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { createRoot } from 'react-dom/client';
|
|
3
|
-
import { Timeline, TimelineProps } from '../../timeline';
|
|
4
|
-
|
|
5
|
-
describe('Timeline', () => {
|
|
6
|
-
let props: TimelineProps;
|
|
7
|
-
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
props = {
|
|
10
|
-
duration: 300,
|
|
11
|
-
value: 15,
|
|
12
|
-
onChange: jest.fn(),
|
|
13
|
-
onRangeChange: jest.fn(),
|
|
14
|
-
zoomLevel: 0,
|
|
15
|
-
};
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe('render()', () => {
|
|
19
|
-
it('renders a timeline', () => {
|
|
20
|
-
const rootElement = document.createElement('div');
|
|
21
|
-
|
|
22
|
-
const root = createRoot(rootElement);
|
|
23
|
-
root.render(<Timeline {...props} />);
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
});
|
package/src/components/index.js
DELETED
package/src/components/index.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# ReproductionWidget
|
|
2
|
-
|
|
3
|
-
<!-- STORY -->
|
|
4
|
-
|
|
5
|
-
<hr>
|
|
6
|
-
|
|
7
|
-
A reproduction player that exposes an object that allows users to play around with the reproduction, e.g., stop/pause it.
|
|
8
|
-
Currently, it supports YouTube videos and a silent mode, meaning a reproduction without associated media, ideal for playing an instrument without any music but with the time running.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## Usage
|
|
12
|
-
|
|
13
|
-
```jsx
|
|
14
|
-
<ReproductionWidget
|
|
15
|
-
trainingMode={true}
|
|
16
|
-
videoId={'jFI-RBqXzhU'}
|
|
17
|
-
onInit={(reproduction) => { reproduction.start() }}
|
|
18
|
-
/>
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
##### Required props
|
|
22
|
-
|
|
23
|
-
| Name | Type | Description |
|
|
24
|
-
|----------------|------------|-------------------------------------------------------------------------------------|
|
|
25
|
-
| `trainingMode` | `boolean` | If true, will reproduce the video with youtube, otherwise, silent mode will be used |
|
|
26
|
-
| `videoId` | `string` | YouTube video id (required if trainingMode === true) |
|
|
27
|
-
| `onInit` | `function` | Fired when the reproduction is ready to use |
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { YouTubeInnerPlayer } from './inner-players/YouTubeInnerPlayer';
|
|
3
|
-
import { PlayAlongInnerPlayer } from './inner-players/PlayAlongInnerPlayer';
|
|
4
|
-
import { Reproduction } from './models/Reproduction';
|
|
5
|
-
import { YouTubePlayer as InnerYouTubePlayer } from 'react-youtube';
|
|
6
|
-
|
|
7
|
-
interface BaseProps {
|
|
8
|
-
trainingMode: boolean;
|
|
9
|
-
onInit: (reproduction: Reproduction) => void;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
interface TrainingProps extends BaseProps {
|
|
13
|
-
trainingMode: true;
|
|
14
|
-
videoId: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface NonTrainingProps extends BaseProps {
|
|
18
|
-
trainingMode: false;
|
|
19
|
-
videoId?: never;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type ReproductionWidgetProps = TrainingProps | NonTrainingProps;
|
|
23
|
-
|
|
24
|
-
export const ReproductionWidget = ({
|
|
25
|
-
trainingMode,
|
|
26
|
-
videoId,
|
|
27
|
-
onInit,
|
|
28
|
-
}: ReproductionWidgetProps) => {
|
|
29
|
-
const DURATION_TO_TEST = 30;
|
|
30
|
-
const TEMPO_TO_TEST = 90;
|
|
31
|
-
const WITH_COUNTING_IN_TEST = true;
|
|
32
|
-
|
|
33
|
-
function onPlayAlongInnerPlayerReadyHandler(event: { target: string }) {
|
|
34
|
-
let newReproduction = Reproduction.newBuilder()
|
|
35
|
-
.withTrainingMode(false)
|
|
36
|
-
.withSongDuration(DURATION_TO_TEST)
|
|
37
|
-
.withSongTempo(TEMPO_TO_TEST)
|
|
38
|
-
.withCountingIn(WITH_COUNTING_IN_TEST)
|
|
39
|
-
.withInnerPlayer(event.target)
|
|
40
|
-
.createReproduction();
|
|
41
|
-
onInit(newReproduction);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function onYouTubeInnerPlayerReadyHandler(event: {
|
|
45
|
-
target: InnerYouTubePlayer;
|
|
46
|
-
}) {
|
|
47
|
-
let newReproduction = Reproduction.newBuilder()
|
|
48
|
-
.withTrainingMode(true)
|
|
49
|
-
.withSongTempo(TEMPO_TO_TEST)
|
|
50
|
-
.withCountingIn(WITH_COUNTING_IN_TEST)
|
|
51
|
-
.withInnerPlayer(event.target)
|
|
52
|
-
.createReproduction();
|
|
53
|
-
onInit(newReproduction);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return (
|
|
57
|
-
<>
|
|
58
|
-
{trainingMode ? (
|
|
59
|
-
<YouTubeInnerPlayer
|
|
60
|
-
videoId={videoId}
|
|
61
|
-
onReady={onYouTubeInnerPlayerReadyHandler}
|
|
62
|
-
/>
|
|
63
|
-
) : (
|
|
64
|
-
<PlayAlongInnerPlayer onReady={onPlayAlongInnerPlayerReadyHandler} />
|
|
65
|
-
)}
|
|
66
|
-
</>
|
|
67
|
-
);
|
|
68
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './ReproductionWidget';
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import React, { useEffect } from 'react';
|
|
2
|
-
|
|
3
|
-
interface Props {
|
|
4
|
-
onReady: (event: { target: string }) => void;
|
|
5
|
-
}
|
|
6
|
-
export const PlayAlongInnerPlayer = ({ onReady }: Props) => {
|
|
7
|
-
useEffect(() => onReady({ target: 'mock' }), []);
|
|
8
|
-
|
|
9
|
-
return <div></div>;
|
|
10
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react';
|
|
2
|
-
import YouTube, { YouTubePlayer as InnerYouTubePlayer } from 'react-youtube';
|
|
3
|
-
|
|
4
|
-
interface Props {
|
|
5
|
-
videoId: string;
|
|
6
|
-
onReady: (event: { target: InnerYouTubePlayer }) => void;
|
|
7
|
-
}
|
|
8
|
-
export const YouTubeInnerPlayer = ({ videoId, onReady }: Props) => {
|
|
9
|
-
const [origin, setOrigin] = useState('');
|
|
10
|
-
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
if (typeof window !== 'undefined') {
|
|
13
|
-
setOrigin(window.location.href);
|
|
14
|
-
}
|
|
15
|
-
}, []);
|
|
16
|
-
|
|
17
|
-
const opts = {
|
|
18
|
-
playerVars: {
|
|
19
|
-
// https://developers.google.com/youtube/player_parameters
|
|
20
|
-
autoplay: 0,
|
|
21
|
-
controls: 0,
|
|
22
|
-
showinfo: 0,
|
|
23
|
-
enablejsapi: 1,
|
|
24
|
-
origin: origin,
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
return (
|
|
28
|
-
<YouTube
|
|
29
|
-
id={'YT-' + videoId}
|
|
30
|
-
className='youtube-player'
|
|
31
|
-
videoId={videoId}
|
|
32
|
-
opts={opts}
|
|
33
|
-
onReady={onReady}
|
|
34
|
-
/>
|
|
35
|
-
);
|
|
36
|
-
};
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { PLAYER_EVENTS } from './PlayerEvents';
|
|
2
|
-
|
|
3
|
-
const dispatchOnReadyHandlers = Symbol();
|
|
4
|
-
const dispatchOnFinishHandlers = Symbol();
|
|
5
|
-
|
|
6
|
-
export class PlayAlongPlayer {
|
|
7
|
-
private readonly duration: number;
|
|
8
|
-
private currentTime: number;
|
|
9
|
-
private isRunning: boolean;
|
|
10
|
-
private currentPlaybackRate: number;
|
|
11
|
-
private innerPlayer: string | null;
|
|
12
|
-
private interval: ReturnType<typeof setInterval> | null = null;
|
|
13
|
-
private [dispatchOnReadyHandlers]: (() => void)[];
|
|
14
|
-
private [dispatchOnFinishHandlers]: (() => void)[];
|
|
15
|
-
|
|
16
|
-
static get EVENTS() {
|
|
17
|
-
return PLAYER_EVENTS;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
constructor(duration: number, innerPlayer: string) {
|
|
21
|
-
this.interval = null;
|
|
22
|
-
this.currentTime = 0;
|
|
23
|
-
this.isRunning = false;
|
|
24
|
-
this.duration = duration;
|
|
25
|
-
this.currentPlaybackRate = 1;
|
|
26
|
-
this.innerPlayer = null;
|
|
27
|
-
|
|
28
|
-
this[dispatchOnFinishHandlers] = [];
|
|
29
|
-
this[dispatchOnReadyHandlers] = [];
|
|
30
|
-
|
|
31
|
-
this.setInnerPlayer(innerPlayer);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
private setInnerPlayer(innerPlayer: string) {
|
|
35
|
-
this.innerPlayer = innerPlayer;
|
|
36
|
-
this.dispatch(PlayAlongPlayer.EVENTS.READY);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
play() {
|
|
40
|
-
this.isRunning = true;
|
|
41
|
-
|
|
42
|
-
const intervalTimeout = 1000;
|
|
43
|
-
|
|
44
|
-
this.interval = setInterval(() => {
|
|
45
|
-
if (this.isRunning) {
|
|
46
|
-
this.currentTime++;
|
|
47
|
-
if (this.currentTime >= this.getDuration()) {
|
|
48
|
-
this.stop();
|
|
49
|
-
this.dispatch(PlayAlongPlayer.EVENTS.FINISH);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}, intervalTimeout);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
pause() {
|
|
56
|
-
this.isRunning = false;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
stop() {
|
|
60
|
-
this.currentTime = 0;
|
|
61
|
-
this.isRunning = false;
|
|
62
|
-
|
|
63
|
-
if (this.interval !== null) {
|
|
64
|
-
clearInterval(this.interval as NodeJS.Timeout);
|
|
65
|
-
this.interval = null;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
seekTo(seconds: number) {
|
|
70
|
-
this.currentTime = seconds;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
getCurrentTime() {
|
|
74
|
-
return this.currentTime;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
getDuration() {
|
|
78
|
-
return this.duration;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
isAvailable() {
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
getAvailablePlaybackRates() {
|
|
86
|
-
return [1];
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
setPlaybackRate(playbackRate: number) {
|
|
90
|
-
if (!this.getAvailablePlaybackRates().includes(playbackRate)) {
|
|
91
|
-
throw new Error(
|
|
92
|
-
`The PlayAlongPlayer doesn't support a playbackRate with value ${playbackRate}`
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
this.currentPlaybackRate = playbackRate;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
on(eventName: keyof typeof PlayAlongPlayer.EVENTS, handler: () => void) {
|
|
99
|
-
switch (eventName) {
|
|
100
|
-
case PlayAlongPlayer.EVENTS.READY:
|
|
101
|
-
return this[dispatchOnReadyHandlers].push(handler);
|
|
102
|
-
case PlayAlongPlayer.EVENTS.FINISH:
|
|
103
|
-
return this[dispatchOnFinishHandlers].push(handler);
|
|
104
|
-
default:
|
|
105
|
-
break;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
dispatch(eventName: keyof typeof PlayAlongPlayer.EVENTS) {
|
|
110
|
-
let handler, i, len;
|
|
111
|
-
let ref: (() => void)[] = [];
|
|
112
|
-
|
|
113
|
-
switch (eventName) {
|
|
114
|
-
case PlayAlongPlayer.EVENTS.READY:
|
|
115
|
-
ref = this[dispatchOnReadyHandlers];
|
|
116
|
-
break;
|
|
117
|
-
case PlayAlongPlayer.EVENTS.FINISH:
|
|
118
|
-
ref = this[dispatchOnFinishHandlers];
|
|
119
|
-
break;
|
|
120
|
-
default:
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
for (i = 0, len = ref.length; i < len; i++) {
|
|
125
|
-
handler = ref[i];
|
|
126
|
-
handler();
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { YouTubePlayer as InnerYouTubePlayer } from 'react-youtube';
|
|
2
|
-
import { PlayAlongPlayer } from './PlayAlongPlayer';
|
|
3
|
-
import { PLAYER_EVENTS } from './PlayerEvents';
|
|
4
|
-
|
|
5
|
-
// https://developers.google.com/youtube/iframe_api_reference
|
|
6
|
-
enum INNER_YOUTUBE_PLAYER_EVENTS {
|
|
7
|
-
VIDEO_UNSTARTED = -1,
|
|
8
|
-
VIDEO_ENDED = 0,
|
|
9
|
-
VIDEO_PLAYING = 1,
|
|
10
|
-
VIDEO_PAUSED = 2,
|
|
11
|
-
VIDEO_BUFFERING = 3,
|
|
12
|
-
VIDEO_CUED = 5,
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
interface INNER_YOUTUBE_PLAYER_StateChangeEvent {
|
|
16
|
-
data: INNER_YOUTUBE_PLAYER_EVENTS;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const dispatchOnReadyHandlers = Symbol();
|
|
20
|
-
const dispatchOnFinishHandlers = Symbol();
|
|
21
|
-
|
|
22
|
-
export class YouTubePlayer {
|
|
23
|
-
private currentTime: number;
|
|
24
|
-
private isRunning: boolean;
|
|
25
|
-
private innerPlayer: InnerYouTubePlayer | number;
|
|
26
|
-
private [dispatchOnReadyHandlers]: (() => void)[];
|
|
27
|
-
private [dispatchOnFinishHandlers]: (() => void)[];
|
|
28
|
-
|
|
29
|
-
static get EVENTS() {
|
|
30
|
-
return PLAYER_EVENTS;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
constructor(innerPlayer: InnerYouTubePlayer) {
|
|
34
|
-
this[dispatchOnFinishHandlers] = [];
|
|
35
|
-
this[dispatchOnReadyHandlers] = [];
|
|
36
|
-
|
|
37
|
-
this.currentTime = 0;
|
|
38
|
-
this.isRunning = false;
|
|
39
|
-
|
|
40
|
-
this.setInnerPlayer(innerPlayer);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
private setInnerPlayer(innerPlayer: InnerYouTubePlayer) {
|
|
44
|
-
this.innerPlayer = innerPlayer;
|
|
45
|
-
this.dispatch(YouTubePlayer.EVENTS.READY);
|
|
46
|
-
|
|
47
|
-
// this is necessary for avoiding the state video cued.
|
|
48
|
-
// When a video is in this state, when user seek to X, the song is played
|
|
49
|
-
this.innerPlayer.playVideo();
|
|
50
|
-
this.innerPlayer.pauseVideo();
|
|
51
|
-
|
|
52
|
-
this.innerPlayer.addEventListener(
|
|
53
|
-
'onStateChange',
|
|
54
|
-
(videoState: INNER_YOUTUBE_PLAYER_StateChangeEvent) => {
|
|
55
|
-
switch (videoState.data) {
|
|
56
|
-
case INNER_YOUTUBE_PLAYER_EVENTS.VIDEO_ENDED:
|
|
57
|
-
this.dispatch(YouTubePlayer.EVENTS.FINISH);
|
|
58
|
-
this.isRunning = false;
|
|
59
|
-
this.currentTime = 0;
|
|
60
|
-
break;
|
|
61
|
-
default:
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
getInnerPlayer() {
|
|
69
|
-
return this.innerPlayer;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
play() {
|
|
73
|
-
const videoPlayer = this.getInnerPlayer();
|
|
74
|
-
videoPlayer.playVideo();
|
|
75
|
-
|
|
76
|
-
this.isRunning = true;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
pause() {
|
|
80
|
-
this.isRunning = false;
|
|
81
|
-
|
|
82
|
-
this.getInnerPlayer().pauseVideo();
|
|
83
|
-
|
|
84
|
-
this.currentTime = this.getInnerPlayer().getCurrentTime();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
stop() {
|
|
88
|
-
this.isRunning = false;
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Hay un issue al llamar a getDuration del video luego de reanudar una canción pausada (devuelve siempre 0)
|
|
92
|
-
* Para evitar que se pierda la información y tener que cargarla de nuevo, se simula un stop pausando y llevando al comienzo
|
|
93
|
-
* videoPlayer.stopVideo();
|
|
94
|
-
*/
|
|
95
|
-
this.getInnerPlayer().pauseVideo();
|
|
96
|
-
|
|
97
|
-
this.seekTo(0);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
seekTo(seconds: number) {
|
|
101
|
-
const videoPlayer = this.getInnerPlayer();
|
|
102
|
-
this.currentTime = seconds;
|
|
103
|
-
|
|
104
|
-
videoPlayer.seekTo(this.currentTime);
|
|
105
|
-
|
|
106
|
-
if (this.isRunning) {
|
|
107
|
-
this.play();
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
getCurrentTime() {
|
|
112
|
-
return this.isRunning
|
|
113
|
-
? this.getInnerPlayer().getCurrentTime()
|
|
114
|
-
: this.currentTime;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
getDuration() {
|
|
118
|
-
if (this.isAvailable()) {
|
|
119
|
-
return this.getInnerPlayer().getDuration();
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
getAvailablePlaybackRates() {
|
|
124
|
-
return this.getInnerPlayer().getAvailablePlaybackRates();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
setPlaybackRate(playbackRate: number) {
|
|
128
|
-
if (!this.getAvailablePlaybackRates().includes(playbackRate)) {
|
|
129
|
-
throw new Error(
|
|
130
|
-
`The PlayAlongPlayer doesn't support a playbackRate with value ${playbackRate}`
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
this.getInnerPlayer().setPlaybackRate(playbackRate);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
isAvailable() {
|
|
137
|
-
return this.getInnerPlayer() !== null;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
on(eventName: keyof typeof PlayAlongPlayer.EVENTS, handler: () => void) {
|
|
141
|
-
switch (eventName) {
|
|
142
|
-
case PlayAlongPlayer.EVENTS.READY:
|
|
143
|
-
return this[dispatchOnReadyHandlers].push(handler);
|
|
144
|
-
case PlayAlongPlayer.EVENTS.FINISH:
|
|
145
|
-
return this[dispatchOnFinishHandlers].push(handler);
|
|
146
|
-
default:
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
dispatch(eventName: keyof typeof PlayAlongPlayer.EVENTS) {
|
|
152
|
-
let handler, i, len;
|
|
153
|
-
let ref: (() => void)[] = [];
|
|
154
|
-
|
|
155
|
-
switch (eventName) {
|
|
156
|
-
case YouTubePlayer.EVENTS.READY:
|
|
157
|
-
ref = this[dispatchOnReadyHandlers];
|
|
158
|
-
break;
|
|
159
|
-
case YouTubePlayer.EVENTS.FINISH:
|
|
160
|
-
ref = this[dispatchOnFinishHandlers];
|
|
161
|
-
break;
|
|
162
|
-
default:
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
for (i = 0, len = ref.length; i < len; i++) {
|
|
167
|
-
handler = ref[i];
|
|
168
|
-
setTimeout(handler, 0);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|