Skip to content

Commit 9f049e9

Browse files
authored
Merge pull request #301 from streamich/audio-formats
Audio formats
2 parents 5873872 + a32bc51 commit 9f049e9

File tree

8 files changed

+116
-11
lines changed

8 files changed

+116
-11
lines changed

README.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
</h1>
55
</div>
66

7+
<div align="center">
8+
<pre>import Embed from 'react-embed';</pre>
9+
</div>
10+
711
<br />
812
<br />
913

@@ -28,23 +32,39 @@
2832
<img src="https://user-images.githubusercontent.com/9773803/53292170-e6fa7b80-37be-11e9-87ab-8b16ab696412.png">
2933
</div>
3034

31-
3235
<br />
3336
<br />
3437

38+
<div align="center">
39+
<h2>
40+
Dark mode
41+
</h2>
42+
</div>
43+
44+
<div align="center">
45+
<pre>&#x3C;Embed isDark url=&#x27;https://twitter.com/hercuppacoffee/status/911958476678561792&#x27; /&#x3E;</pre>
46+
<img src="https://user-images.githubusercontent.com/9773803/80277289-44a19500-86ee-11ea-8dc7-0d12888cbc2d.png">
47+
</div>
3548

3649
<div align="center">
3750
<h2>
38-
Usage
51+
Responsive
3952
</h2>
40-
<pre>import Embed from 'react-embed';</pre>
4153
</div>
4254

55+
<div align="center">
56+
<pre>&#x3C;Embed url=&#x27;...&#x27; /&#x3E;</pre>
57+
<img src="https://user-images.githubusercontent.com/9773803/80277360-b548b180-86ee-11ea-9b25-3eaa10027ca6.png">
58+
</div>
59+
60+
<div align="center">
61+
<pre>&#x3C;Embed width={300} url=&#x27;...&#x27; /&#x3E;</pre>
62+
<img src="https://user-images.githubusercontent.com/9773803/80277394-e923d700-86ee-11ea-80da-9ff0aaab9d8f.png">
63+
</div>
4364

4465
<br />
4566
<br />
4667

47-
4868
<div align="center">
4969
<h2>
5070
Supported
@@ -70,3 +90,5 @@
7090
- Twitter Tweet
7191
- Vimeo
7292
- YouTube
93+
- Audio files: `.mp3`, `.wav`, `.weba`, `.aac`, `.oga`, `.m4a`, `.mp4`, `.ogg`, `.opus`, `.ts`, `.wma`, `.mp4a`, `.mpga`, `.mp2`, `.mp2a`, `.m2a`, `.m3a`,
94+
- Video files: `.spx`, `.mp4`, `.og`, `.ogv`, `.webm`, `.mov`, `.m4v`, `.m3u8`, `.mpd`

src/ReactEmbed.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export interface ParsedUrl {
1515
export type EmbedBlockId = string;
1616
export interface BlockProps extends ParsedUrl {
1717
id: EmbedBlockId;
18+
width: number;
19+
isDark: boolean;
1820
renderVoid: (error?: Error) => React.ReactElement<any> | null;
1921
renderWrap: ReactEmbedWrapRenderer;
2022
}
@@ -58,11 +60,28 @@ const renderNull = () => null;
5860
const renderWrap = (children) => children;
5961

6062
export interface ReactEmbedProps {
63+
/**
64+
* URL to display.
65+
*/
6166
url: string;
67+
68+
/**
69+
* True if dark mode enable. In that case will try to render content on dark
70+
* background.
71+
*/
72+
isDark?: boolean;
73+
74+
/**
75+
* Number of pixels the maximum space available to the component. If not provided
76+
* defaults to window width.
77+
*/
78+
width?: number;
79+
6280
blocks?: Blocks;
6381
router?: ReactEmbedRouter;
6482
render?: ReactEmbedRenderer;
6583
fallback?: NonNullable<React.ReactNode> | null;
84+
6685
/**
6786
* Called on error or when `react-embed` does not know how render a URL.
6887
* If called on on error, error will available in `error` argument.
@@ -78,6 +97,8 @@ export interface ReactEmbedState {
7897

7998
export class ReactEmbed extends React.PureComponent<ReactEmbedProps, ReactEmbedState> {
8099
static defaultProps = {
100+
width: typeof window === 'object' ? window.innerWidth : 0,
101+
isDark: false,
81102
blocks: defaultBlocks,
82103
router: defaultRouter,
83104
render: defaultRender,

src/__story__/react-simple-player.story.tsx

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,54 @@ import * as React from 'react';
22
import {storiesOf} from '@storybook/react';
33
import Embed from '..';
44

5-
storiesOf('react-simple-player', module).add('.mp3', () => {
6-
return <Embed url={'https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3'} />;
5+
storiesOf('react-simple-player/format', module)
6+
.add('.mp3', () => {
7+
return <Embed url={'https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3'} />;
8+
})
9+
.add('.wav', () => {
10+
return <Embed url={'https://file-examples.com/wp-content/uploads/2017/11/file_example_WAV_1MG.wav'} />;
11+
})
12+
.add('.aac', () => {
13+
return <Embed url={'https://dl.espressif.com/dl/audio/ff-16b-2c-44100hz.aac'} />;
14+
})
15+
.add('.m4a', () => {
16+
return <Embed url={'https://dl.espressif.com/dl/audio/ff-16b-2c-44100hz.m4a'} />;
17+
})
18+
.add('.mp4', () => {
19+
return <Embed url={'https://dl.espressif.com/dl/audio/ff-16b-2c-44100hz.mp4'} />;
20+
})
21+
.add('.ogg', () => {
22+
return <Embed url={'https://dl.espressif.com/dl/audio/ff-16b-2c-44100hz.ogg'} />;
23+
})
24+
.add('.opus', () => {
25+
return <Embed url={'https://dl.espressif.com/dl/audio/ff-16b-2c-44100hz.opus'} />;
26+
})
27+
.add('.wma', () => {
28+
return <Embed url={'https://dl.espressif.com/dl/audio/ff-16b-2c-44100hz.wma'} />;
29+
})
30+
.add('.mpga', () => {
31+
return <Embed url={'https://example-files.online-convert.com/audio/mpga/example.mpga'} />;
32+
})
33+
.add('.mp2', () => {
34+
return <Embed url={'https://filesamples.com/samples/audio/mp2/sample1.mp2'} />;
35+
});
36+
37+
storiesOf('react-simple-player/widths', module)
38+
.add('300px', () => {
39+
return (
40+
<div style={{width: 300}}>
41+
<Embed url={'https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3'} width={300} />
42+
</div>
43+
);
44+
})
45+
.add('500px', () => {
46+
return (
47+
<div style={{width: 500}}>
48+
<Embed url={'https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3'} width={500} />
49+
</div>
50+
);
51+
});
52+
53+
storiesOf('react-simple-player', module).add('dark mode', () => {
54+
return <Embed isDark url={'https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3'} />;
755
});

src/__story__/tweet.story.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ storiesOf('tweet', module)
1313
<Embed url={'https://twitter.com/hercuppacoffee/status/911958476678561792'} />
1414
</Box>
1515
);
16+
})
17+
.add('[isDark]', () => {
18+
return <Embed url={'https://twitter.com/hercuppacoffee/status/911958476678561792'} isDark />;
1619
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const MATCH_AUDIO_FILE = /\.(mp3|wav|weba|aac|oga)($|\?)/i;
1+
const MATCH_AUDIO_FILE = /\.(mp3|wav|weba|aac|oga|m4a|mp4|ogg|opus|ts|wma|mpga)($|\?)/i;
22
const canPlay = (url: string): boolean => MATCH_AUDIO_FILE.test(url);
33

44
export default canPlay;

src/blocks/react-simple-player/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import * as React from 'react';
22
import {BlockProps} from '../..';
33
import {Player} from 'react-simple-player';
44

5-
const SimplePlayerWrapper: React.SFC<BlockProps> = ({url, renderWrap}) => {
6-
return renderWrap(<Player src={url} height={50} />);
5+
const SimplePlayerWrapper: React.FC<BlockProps> = ({url, isDark, width, renderWrap}) => {
6+
return renderWrap(
7+
<Player src={url} height={50} hideVolume={width < 500} grey={isDark ? [20, 23, 26] : [240, 243, 246]} />,
8+
);
79
};
810

911
export default SimplePlayerWrapper;

src/blocks/tweet/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class TwitterTweet extends React.PureComponent<BlockProps, {}> {
2222
console.error('Failed to load Twitter lib.');
2323
return;
2424
}
25-
wnd.twttr.widgets.createTweet(this.props.id, this.refs.ref);
25+
wnd.twttr.widgets.createTweet(this.props.id, this.refs.ref, {theme: this.props.isDark ? 'dark' : 'light'});
2626
});
2727
}
2828

src/renderer.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@ import {ReactEmbedRenderer} from '.';
44
const renderer: ReactEmbedRenderer = (Block: any, id, props, state) => {
55
const renderVoid = (error) => props.renderVoid!(props, state, error);
66

7-
return <Block {...state.url} id={id} renderWrap={props.renderWrap!} renderVoid={renderVoid} />;
7+
return (
8+
<Block
9+
{...state.url}
10+
id={id}
11+
width={props.width}
12+
isDark={props.isDark!}
13+
renderWrap={props.renderWrap!}
14+
renderVoid={renderVoid}
15+
/>
16+
);
817
};
918

1019
export default renderer;

0 commit comments

Comments
 (0)