├── .babelrc
├── .eslintrc
├── .gitignore
├── .npmignore
├── LICENSE
├── README.md
├── example
├── .babelrc
├── files
│ └── George_Gershwin_playing_Rhapsody_in_Blue.ogg
├── index.html
├── js
│ └── main.jsx
├── package-lock.json
├── package.json
└── webpack.config.js
├── package-lock.json
├── package.json
├── src
└── index.tsx
├── test
├── fixtures
│ └── turkish_march.ogg
└── index.test.js
├── tsconfig.json
└── webpack.config.js
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | "@babel/preset-env",
4 | "@babel/preset-react",
5 | [
6 | "@babel/preset-typescript",
7 | {
8 | "isTSX": true,
9 | "allExtensions": true
10 | }
11 | ]
12 | ],
13 | "plugins": [
14 | "@babel/plugin-proposal-class-properties",
15 | "react-hot-loader/babel"
16 | ]
17 | }
18 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "airbnb",
3 | "globals": {
4 | "document": true,
5 | },
6 | "rules": {
7 | "jsx-a11y/media-has-caption": 0,
8 | "no-unused-expressions": [2, { "allowShortCircuit": true }],
9 | "prefer-destructuring": 0,
10 | "react/destructuring-assignment": 0 ,
11 | "react/jsx-one-expression-per-line": 0
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | dist/
2 | node_modules/
3 | .DS_Store
4 | npm-debug.log
5 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | src/
2 | example/
3 | spec/
4 | karma.conf.js
5 | webpack.config.js
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Justin McCandless
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # React Audio Player
2 | This is a light React wrapper around the HTML5 audio tag. It provides the ability to manipulate the player and listen to events through a nice React interface.
3 |
4 | ## Installation
5 |
6 | npm install --save react-audio-player
7 |
8 | Also be sure you have `react` and `react-dom` installed in your app at version 15 or above.
9 |
10 | ## Usage
11 |
12 | import ReactAudioPlayer from 'react-audio-player';
13 | //...
14 |
19 |
20 | ### Example
21 |
22 | See the example directory for a basic working example of using this project. To run it locally, run `npm install` in the example directory and then `npm start`.
23 |
24 | ## Props
25 |
26 | ### Props - Native/React Attributes
27 | See the [audio tag documentation](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio) for detailed explanations of these attributes.
28 |
29 | Prop | Type | Default | Notes
30 | --- | --- | --- | ---
31 | `autoPlay` | Boolean | false | ---
32 | `children` | Element | null | ---
33 | `className` | String | *empty string* | ---
34 | `controls` | Boolean | false | ---
35 | `crossOrigin` | String | *empty string* | See [MDN's article on CORS](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes) for more about this attribute.
36 | `controlsList` | String | *empty string* | For Chrome 58+. Only available in React 15.6.2+
37 | `id` | String | *empty string* | ---
38 | `loop` | Boolean | false | ---
39 | `muted` | Boolean | false | ---
40 | `volume` | Number | 1.0 | ---
41 | `preload` | String | 'metadata' | ---
42 | `src` | String | *empty string* | ---
43 | `style` | Object | --- | ---
44 |
45 | ### Props - Events
46 |
47 | Prop | Type | Description
48 | --- | --- | ---
49 | `listenInterval` | Number | Indicates how often to call the `onListened` prop during playback, in milliseconds. Default is 10000.
50 | `onAbort` | Function | called when unloading the audio player, like when switching to a different src file. Passed the event.
51 | `onCanPlay` | Function | called when enough of the file has been downloaded to be able to start playing. Passed the event.
52 | `onCanPlayThrough` | Function | called when enough of the file has been downloaded to play through the entire file. Passed the event.
53 | `onEnded` | Function | called when playback has finished to the end of the file. Passed the event.
54 | `onError` | Function | called when the audio tag encounters an error. Passed the event.
55 | `onListen` | Function | called every `listenInterval` milliseconds during playback. Passed the event.
56 | `onPause` | Function | called when the user pauses playback. Passed the event.
57 | `onPlay` | Function | called when the user taps play. Passed the event.
58 | `onSeeked` | Function | called when the user drags the time indicator to a new time. Passed the event.
59 | `onVolumeChanged` | Function | called when the user changes the volume, such as by dragging the volume slider |
60 | `onLoadedMetadata` | Function | called when the metadata for the given audio file has finished downloading. Passed the event.
61 |
62 | ## Advanced Usage
63 |
64 | ### Access to the audio element
65 | You can get direct access to the underlying audio element. First get a ref to ReactAudioPlayer:
66 |
67 | { this.rap = element; }}
69 | />
70 |
71 | Then you can access the audio element like this:
72 |
73 | this.rap.audioEl
74 |
75 | This is especially useful if you need access to read-only attributes of the audio tag such as `buffered` and `played`. See the [audio tag documentation](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio) for more on these attributes.
76 |
--------------------------------------------------------------------------------
/example/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | "@babel/preset-env",
4 | "@babel/preset-react"
5 | ],
6 | "plugins": [
7 | "react-hot-loader/babel"
8 | ]
9 | }
10 |
--------------------------------------------------------------------------------
/example/files/George_Gershwin_playing_Rhapsody_in_Blue.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/justinmc/react-audio-player/27b0de14b6dce16723430b42e4cfabd3af295b78/example/files/George_Gershwin_playing_Rhapsody_in_Blue.ogg
--------------------------------------------------------------------------------
/example/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | react-audio-player example
7 |
8 |
9 |
10 |
11 |
14 |
15 |
16 |