UNPKG

4.64 kBMarkdownView Raw
1<h1>
2 Material UI Player
3</h1>
4
5[![NPM version][npm-image]][npm-url]
6![Types included][types-image]
7[![install size](https://packagephobia.com/badge?p=material-ui-player@0.1.12)](https://packagephobia.com/result?p=material-ui-player@0.1.12)
8
9[npm-image]: https://img.shields.io/npm/v/material-ui-player.svg
10[npm-url]: https://npmjs.org/package/material-ui-player
11[types-image]: https://badgen.net/npm/types/tslib
12
13<p align='center'>
14 Simple React components for playing audio and video, using <a href="https://material-ui.com/">Material UI</a>
15</p>
16<ul>
17<li>AudioCard: Audio element with controls</li>
18<li>VideoCard: Video element with controls</li>
19<li>SoundButton: IconButton to only play audio files (ideal for short audios)</li>
20</ul>
21
22## Contents
23
24- [Why use this package](#why-use-this-package)
25- [Usage](#usage)
26- [Props](#props)
27- [Callback props](#callback-props)
28- [Note](#note)
29- [License](#license)
30
31### Why use this package
32
33- Allow customization on traditional ```<audio>``` and ```<video>``` HTML elements
34- Easy play media files stored in Firebase Storage or anywhere need to retrieve the download URL
35- Material-UI components like : theming, customizations and low level components
36- Use modern React hook and coding conventions
37- Documentation made with Storybook
38
39### Usage
40
41```bash
42npm install material-ui-player # or yarn add material-ui-player
43```
44
45```jsx
46import React from 'react'
47import { AudioCard, VideoCard } from 'material-ui-player'
48
49// Relative URL - play a media from same origin
50<AudioCard src={'/audio.mp3'} />
51<VideoCard src={'/video.mp4'} />
52<SoundButton src={'/audio.mp3'} />
53
54// Absolute URL - play a media from external source
55<AudioCard src={'https://file-examples-com.github.io/uploads/2017/11/file_example_MP3_1MG.mp3'} />
56<VideoCard src={'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4'} />
57<SoundButton src={'https://file-examples-com.github.io/uploads/2017/11/file_example_MP3_1MG.mp3'} />
58
59// Promise retrieve URL
60<AudioCard src={fetch('<my url>')} />
61<VideoCard src={fetch('<my url>')} />
62<SoundButton src={fetch('<my url>')} />
63
64```
65### Props
66
67Prop | Description | Default | Component
68---- | ----------- | ------- | ---------
69`src` | `string` or `Promise<string>` or `() => string` or `() => Promise<string>` <br /> - The url of a media to play&nbsp; ◦ &nbsp;Can be a relative or absolute url <br /> A Promise resolved into a string (the url) after Play button clicked. This case can be useful when you are using Firebase Storage, where you need to call an API to retrieve the download Url. | (mandatory) | all
70`forward` | Set to `true` or falsy to show forward button | `undefined` | AudioCard, VideoCard
71`backward` | Set to `true` or falsy to show backward button | `undefined` | AudioCard, VideoCard
72`autoplay` | Set to `true` or falsy to set autoplay on audio | `undefined` | AudioCard, VideoCard
73`loop` | Set to `true` or falsy to set loop on audio | `undefined` | AudioCard, VideoCard
74`width` | Set the width of the player | Audio: `undefined` (fit parent container) <br /> Video: `undefined` (video maintain original size, card fit parent container) | AudioCard, VideoCard
75`speed` | Set to `true` or falsy to show speed control | `undefined` | AudioCard, VideoCard
76`mute` | Set to `true` or falsy to show mute button | `undefined` | AudioCard, VideoCard
77`fadeSettings` | Object with `fadeInTime` and `fadeOutTime` (number, seconds) to fadein and fadeout video | `undefined` | VideoCard
78`thickness` | Set sliders line thickness (`thin`, `medium` or `large`) | `medium` | AudioCard, VideoCard
79`background` | Set container card background | `inherit` | all
80`PlayProps` | enable customization using Material UI IconButton props | `undefined` | all
81`BackwardProps`, `StopProps`, `PauseProps`, `ForwardProps`, `MuteProps` | enable customization using Material UI IconButton props | `undefined` | AudioCard, VideoCard
82
83
84### Callback props
85
86Callback props take a function that gets fired on various player events:
87
88Prop | Description | Component
89---- | ----------- | ---------
90`onForwardClick` | Called when forward button is clicked | AudioCard, VideoCard
91`onBackwardClick` | Called when backward button is clicked | AudioCard, VideoCard
92`onEnded` | Called when media ended | AudioCard, VideoCard
93
94
95### Note
96Please Note: this module has following peerDependencies:
97```
98 "@material-ui/core": "^4.0.0",
99 "@material-ui/icons": "^4.0.0",
100 "react": "^17.0.0",
101 "react-dom": "^17.0.0",
102```
103
104### License
105
106Released under MIT License
107
108