@ldelia/react-media 0.3.0 → 0.4.1
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 +1 -4
- package/package.json +2 -1
- package/src/components/index.js +1 -0
- package/src/components/index.ts +1 -0
- package/src/components/reproduction-widget/README.md +27 -0
- package/src/components/reproduction-widget/ReproductionWidget.js +29 -0
- package/src/components/reproduction-widget/ReproductionWidget.tsx +68 -0
- package/src/components/reproduction-widget/index.js +1 -0
- package/src/components/reproduction-widget/index.tsx +1 -0
- package/src/components/reproduction-widget/inner-players/PlayAlongInnerPlayer.js +5 -0
- package/src/components/reproduction-widget/inner-players/PlayAlongInnerPlayer.tsx +10 -0
- package/src/components/reproduction-widget/inner-players/YouTubeInnerPlayer.js +21 -0
- package/src/components/reproduction-widget/inner-players/YouTubeInnerPlayer.tsx +36 -0
- package/src/components/reproduction-widget/models/Player/PlayAlongPlayer.js +97 -0
- package/src/components/reproduction-widget/models/Player/PlayAlongPlayer.ts +129 -0
- package/src/components/reproduction-widget/models/Player/PlayerEvents.js +4 -0
- package/src/components/reproduction-widget/models/Player/PlayerEvents.ts +4 -0
- package/src/components/reproduction-widget/models/Player/YouTubePlayer.js +126 -0
- package/src/components/reproduction-widget/models/Player/YouTubePlayer.ts +171 -0
- package/src/components/reproduction-widget/models/Reproduction.js +214 -0
- package/src/components/reproduction-widget/models/Reproduction.ts +272 -0
- package/src/components/reproduction-widget/models/ReproductionBuilder.js +51 -0
- package/src/components/reproduction-widget/models/ReproductionBuilder.ts +70 -0
- package/src/stories/reproduction-widget.stories.js +16 -0
- package/src/stories/reproduction-widget.stories.tsx +23 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { YouTubePlayer } from './Player/YouTubePlayer';
|
|
2
|
+
import { PlayAlongPlayer } from './Player/PlayAlongPlayer';
|
|
3
|
+
import { Reproduction } from './Reproduction';
|
|
4
|
+
import { YouTubePlayer as InnerYouTubePlayer } from 'react-youtube';
|
|
5
|
+
|
|
6
|
+
export class ReproductionBuilder {
|
|
7
|
+
private trainingMode: boolean;
|
|
8
|
+
private requiresCountingIn: boolean;
|
|
9
|
+
private songDuration: number | null;
|
|
10
|
+
private songTempo: number | null;
|
|
11
|
+
private innerPlayer: InnerYouTubePlayer | string;
|
|
12
|
+
|
|
13
|
+
constructor() {
|
|
14
|
+
this.trainingMode = false;
|
|
15
|
+
this.requiresCountingIn = false;
|
|
16
|
+
this.songDuration = null;
|
|
17
|
+
this.songTempo = null;
|
|
18
|
+
this.innerPlayer = null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
withSongDuration(songDuration: number) {
|
|
22
|
+
this.songDuration = songDuration;
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
withSongTempo(songTempo: number) {
|
|
27
|
+
this.songTempo = songTempo;
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
withTrainingMode(trainingMode: boolean) {
|
|
32
|
+
this.trainingMode = trainingMode;
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
withCountingIn(requiresCountingIn: boolean) {
|
|
37
|
+
this.requiresCountingIn = requiresCountingIn;
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
withInnerPlayer(innerPlayer: InnerYouTubePlayer | string) {
|
|
42
|
+
this.innerPlayer = innerPlayer;
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
createReproduction() {
|
|
47
|
+
if (this.requiresCountingIn && this.songTempo === null) {
|
|
48
|
+
throw new Error('The song tempo is mandatory');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (this.innerPlayer === null) {
|
|
52
|
+
throw new Error('The inner player was not provided.');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let player;
|
|
56
|
+
if (this.trainingMode) {
|
|
57
|
+
player = new YouTubePlayer(this.innerPlayer);
|
|
58
|
+
} else {
|
|
59
|
+
if (this.songDuration === null) {
|
|
60
|
+
throw new Error('The song duration is mandatory');
|
|
61
|
+
}
|
|
62
|
+
player = new PlayAlongPlayer(this.songDuration, this.innerPlayer);
|
|
63
|
+
}
|
|
64
|
+
return new Reproduction(
|
|
65
|
+
player,
|
|
66
|
+
this.requiresCountingIn,
|
|
67
|
+
this.songTempo || 0
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ReproductionWidget } from '../components/reproduction-widget';
|
|
3
|
+
export default {
|
|
4
|
+
title: 'ReproductionWidget',
|
|
5
|
+
component: ReproductionWidget,
|
|
6
|
+
argTypes: {
|
|
7
|
+
onInit: { action: 'initiated' },
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
const Template = (args) => (React.createElement(ReproductionWidget, Object.assign({}, args)));
|
|
11
|
+
export const Default = Template.bind({});
|
|
12
|
+
Default.args = {
|
|
13
|
+
trainingMode: true,
|
|
14
|
+
videoId: 'jFI-RBqXzhU',
|
|
15
|
+
onInit: (reproduction) => { reproduction.start(); }
|
|
16
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Meta, StoryFn } from '@storybook/react';
|
|
3
|
+
import { ReproductionWidget, ReproductionWidgetProps } from '../components/reproduction-widget';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: 'ReproductionWidget',
|
|
7
|
+
component: ReproductionWidget,
|
|
8
|
+
argTypes: {
|
|
9
|
+
onInit: { action: 'initiated' },
|
|
10
|
+
},
|
|
11
|
+
} as Meta;
|
|
12
|
+
|
|
13
|
+
const Template: StoryFn<ReproductionWidgetProps> = (args: ReproductionWidgetProps) => (
|
|
14
|
+
<ReproductionWidget
|
|
15
|
+
{...args}
|
|
16
|
+
/>
|
|
17
|
+
);
|
|
18
|
+
export const Default = Template.bind({});
|
|
19
|
+
Default.args = {
|
|
20
|
+
trainingMode: true,
|
|
21
|
+
videoId: 'jFI-RBqXzhU',
|
|
22
|
+
onInit: (reproduction) => { reproduction.start() }
|
|
23
|
+
};
|