navidrome-music-player 4.25.0 → 4.25.2
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 +5 -680
- package/assets/index.css +1 -1
- package/assets/index.module.css +1 -1
- package/dist/navidrome-music-player.min.js +1 -1
- package/dist/navidrome-music-player.min.js.LICENSE.txt +4 -17
- package/es/components/AudioListsPanel.js +14 -16
- package/es/components/CircleProcessBar.js +4 -7
- package/es/components/PlayModeTip.js +3 -5
- package/es/components/PlayModel.js +1 -3
- package/es/components/PlayerMobile.js +26 -28
- package/es/config/audioState.js +0 -2
- package/es/index.js +461 -817
- package/es/locale/index.js +5 -5
- package/es/lyric.js +8 -30
- package/es/utils.js +16 -29
- package/lib/components/AudioListsPanel.js +18 -31
- package/lib/components/CircleProcessBar.js +8 -17
- package/lib/components/Icon.js +43 -72
- package/lib/components/PlayModeTip.js +7 -18
- package/lib/components/PlayModel.js +5 -16
- package/lib/components/PlayerMobile.js +30 -44
- package/lib/config/animate.js +1 -3
- package/lib/config/audioState.js +3 -7
- package/lib/config/keycode.js +1 -2
- package/lib/config/locale.js +2 -3
- package/lib/config/mediaQuery.js +2 -3
- package/lib/config/mode.js +2 -3
- package/lib/config/playMode.js +2 -3
- package/lib/config/player.js +2 -4
- package/lib/config/propTypes.js +3 -11
- package/lib/config/slider.js +3 -5
- package/lib/config/sortable.js +2 -3
- package/lib/config/theme.js +2 -3
- package/lib/config/volumeFade.js +2 -3
- package/lib/index.js +468 -867
- package/lib/locale/en_US.js +3 -8
- package/lib/locale/index.js +7 -13
- package/lib/locale/zh_CN.js +3 -8
- package/lib/lyric.js +10 -34
- package/lib/utils.js +24 -49
- package/package.json +4 -1
- package/CHANGELOG.md +0 -268
package/README.md
CHANGED
|
@@ -1,682 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
<img alt="logo" src="https://github.com/lijinke666/react-music-player/blob/master/assetsImg/logo.png?raw=true" width="100" max-width="100%">
|
|
3
|
-
</p>
|
|
1
|
+
## Navidrome Music Player (temporary)
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
react-
|
|
7
|
-
</h1>
|
|
3
|
+
This is a fork of [react-jinke-music-player](https://github.com/lijinke666/react-music-player) to
|
|
4
|
+
[fix a bug](https://github.com/lijinke666/react-music-player/issues/349#issuecomment-840522656) for Navidrome.
|
|
8
5
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
</h4>
|
|
12
|
-
|
|
13
|
-
<p align="center">
|
|
14
|
-
<a href="https://www.npmjs.com/package/react-jinke-music-player" title="npm">
|
|
15
|
-
<img src="https://img.shields.io/npm/dm/react-jinke-music-player.svg?style=flat-square" alt="npm"/>
|
|
16
|
-
</a>
|
|
17
|
-
<a href="https://www.npmjs.com/package/react-jinke-music-player" title="npm">
|
|
18
|
-
<img src="https://img.shields.io/npm/l/react-jinke-music-player.svg?style=flat-square" alt="npm"/>
|
|
19
|
-
</a>
|
|
20
|
-
<a href="https://github.com/lijinke666/react-music-player/actions">
|
|
21
|
-
<img src="https://github.com/lijinke666/react-music-player/workflows/CI/badge.svg" />
|
|
22
|
-
</a>
|
|
23
|
-
<a href="https://badge.fury.io/js/react-jinke-music-player" title="npm">
|
|
24
|
-
<img src="https://img.shields.io/npm/v/react-jinke-music-player.svg?style=flat-square" alt="npm version"/>
|
|
25
|
-
</a>
|
|
26
|
-
<a href="https://lgtm.com/projects/g/lijinke666/react-music-player/context:javascript">
|
|
27
|
-
<img alt="Language grade: JavaScript" src="https://img.shields.io/lgtm/grade/javascript/g/lijinke666/react-music-player.svg?logo=lgtm&logoWidth=18"/>
|
|
28
|
-
</a>
|
|
29
|
-
<a href="https://codecov.io/gh/lijinke666/react-music-player">
|
|
30
|
-
<img src="https://codecov.io/gh/lijinke666/react-music-player/branch/master/graph/badge.svg" />
|
|
31
|
-
</a>
|
|
32
|
-
<img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/react-jinke-music-player?style=flat-square">
|
|
33
|
-
<a href="https://david-dm.org/lijinke666/react-music-player" title="dependencies status"><img src="https://david-dm.org/lijinke666/react-music-player/status.svg"/></a>
|
|
34
|
-
<a href="https://david-dm.org/lijinke666/react-music-player?type=dev" title="devDependencies status"><img src="https://david-dm.org/lijinke666/react-music-player/dev-status.svg"/></a>
|
|
35
|
-
<a href="https://github.com/semantic-release/semantic-release" title="semantic-release">
|
|
36
|
-
<img src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg" alt="semantic release"/>
|
|
37
|
-
</a>
|
|
38
|
-
<a href="https://visitor-badge.glitch.me" title="visitor">
|
|
39
|
-
<img src="https://visitor-badge.glitch.me/badge?page_id=lijinke666.react-music-player" alt="visitor"/>
|
|
40
|
-
</a>
|
|
41
|
-
</p>
|
|
42
|
-
|
|
43
|
-
<p align="center">
|
|
44
|
-
<a href="https://github.com/lijinke666/react-music-player/blob/master/CN.md">
|
|
45
|
-
中文文档
|
|
46
|
-
</a>
|
|
47
|
-
</p>
|
|
48
|
-
|
|
49
|
-
## :package: Installation
|
|
50
|
-
|
|
51
|
-
using `yarn` :
|
|
52
|
-
|
|
53
|
-
```bash
|
|
54
|
-
yarn add react-jinke-music-player
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
using `npm` :
|
|
58
|
-
|
|
59
|
-
```bash
|
|
60
|
-
npm install react-jinke-music-player --save
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## :framed_picture: Screenshots
|
|
64
|
-
|
|
65
|
-
> mini mode <br/>
|
|
66
|
-
|
|
67
|
-

|
|
68
|
-
|
|
69
|
-
> Light Theme <br/>
|
|
70
|
-
|
|
71
|
-

|
|
72
|
-
|
|
73
|
-
> Dark Theme <br/>
|
|
74
|
-
|
|
75
|
-

|
|
76
|
-
|
|
77
|
-
> mobile <br/>
|
|
78
|
-
|
|
79
|
-

|
|
80
|
-
|
|
81
|
-
## :sparkles: Feature list
|
|
82
|
-
|
|
83
|
-
- [x] Beautiful ui and animation
|
|
84
|
-
- [x] Responsive
|
|
85
|
-
- [x] Support theme switch
|
|
86
|
-
- [x] Support typescript (d.ts)
|
|
87
|
-
- [x] Support lyric
|
|
88
|
-
- [x] Support audio list sortable
|
|
89
|
-
- [x] Play list
|
|
90
|
-
- [x] Full player features
|
|
91
|
-
- [x] [Server-Side Rendering](#bulb-server-side-rendering)
|
|
92
|
-
- [x] [Import in Browser](#bulb-import-in-browser)
|
|
93
|
-
- [x] [Complete hook function](#clipboard-api)
|
|
94
|
-
- [x] [Custom operation ui](#bulb-custom-operation-ui)
|
|
95
|
-
- [x] [Custom downloader](#bulb-custom-downloader)
|
|
96
|
-
- [x] [Support destroy player](#bulb-destroy-player)
|
|
97
|
-
- [x] [Support glass background](#bulb-glass-bg)
|
|
98
|
-
- [x] [Media session](#bulb-media-session) (v4.11.0)
|
|
99
|
-
- [x] [Support internationalization](#bulb-internationalization) (v4.11.0)
|
|
100
|
-
- [x] [Customize theme](#bulb-customize-theme) (v4.11.0)
|
|
101
|
-
- [x] [Customize audio duration](#bulb-customize-audio-duration) (v4.13.0)
|
|
102
|
-
- [x] [Customize player icon](#bulb-customize-player-icon) (v4.17.0)
|
|
103
|
-
- [x] [Follow the theme of the system](#bulb-follow-the-theme-of-the-system) (v4.16.0)
|
|
104
|
-
- [x] [Audio volume fadeIn/fadeOut](#bulb-audio-volume-fade-in-and-fade-out) (v4.20.0)
|
|
105
|
-
|
|
106
|
-
## :eyes: Example
|
|
107
|
-
|
|
108
|
-
> live example :
|
|
109
|
-
|
|
110
|
-
- [https://lijinke666.github.io/react-music-player/](https://lijinke666.github.io/react-music-player/)
|
|
111
|
-
|
|
112
|
-
> local example : [http://localhost:8081/](http://localhost:8081/)
|
|
113
|
-
|
|
114
|
-
[Source Code](https://github.com/lijinke666/react-music-player/blob/master/example/example.js)
|
|
115
|
-
|
|
116
|
-
## :memo: Usage
|
|
117
|
-
|
|
118
|
-
```jsx
|
|
119
|
-
import React from 'react'
|
|
120
|
-
import ReactDOM from 'react-dom'
|
|
121
|
-
import ReactJkMusicPlayer from 'react-jinke-music-player'
|
|
122
|
-
import 'react-jinke-music-player/assets/index.css'
|
|
123
|
-
|
|
124
|
-
ReactDOM.render(
|
|
125
|
-
<ReactJkMusicPlayer {...options} />,
|
|
126
|
-
document.getElementById('root'),
|
|
127
|
-
)
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
## :clipboard: API
|
|
131
|
-
|
|
132
|
-
| Name | Type | Default | Description |
|
|
133
|
-
| ---- | ---- | ------- | ----------- |
|
|
134
|
-
| className | `string` | `-` | Additional CSS class for the root DOM node |
|
|
135
|
-
| audioLists | [AudioListProps[]](#bulb-audiolistprops) | `-` | [Detail](#bulb-audiolistprops) |
|
|
136
|
-
| theme | `light` \| `dark` \| `auto` | `dark` | color of the music player theme `dark`, `light`, `auto (follow system)` | `light` |
|
|
137
|
-
| locale | `zh_CN` \| `en_US` \| [CustomLocale](#bulb-internationalization) | `en_US` | [Detail](#bulb-internationalization) | `light` |
|
|
138
|
-
| icon | [Customize player icon](#bulb-customize-player-icon) | `-` | [Customize player icon](#bulb-customize-player-icon) | `light` |
|
|
139
|
-
| defaultPosition | `object` | `{top:0,left:0}` | audio controller initial position with `left,top,right,and bottom` |
|
|
140
|
-
| playModeShowTime | `number` | `600` | play mode toggle show time (ms) |
|
|
141
|
-
| bounds | `object`,`number` | `body` | specifies movement boundaries. Accepted values: `parent` restricts movement within the node's offsetParent (nearest node with position relative or absolute), or a selector, restricts movement within the targeted node An object with `left, top, right, and bottom` properties. These indicate how far in each direction the draggable can be moved. |
|
|
142
|
-
| preload | `boolean`,`string` | `false` | Whether to load audio immediately after the page loads. can be set to `auto | metadata | none` `true | false`if`preload=true` preload="auto" |
|
|
143
|
-
| remember | `boolean` | `false` | The next time you access the player, do you keep the last state |
|
|
144
|
-
| glassBg | `boolean` | `false` | Whether the player's background displays frosted glass effect |
|
|
145
|
-
| remove | `boolean` | `true` | The Audio Can be deleted |
|
|
146
|
-
| defaultPlayIndex | `number` | `0` | Default play index of the audio player |
|
|
147
|
-
| playIndex | `number` | `0` | play index of the audio player |
|
|
148
|
-
| defaultPlayMode | `string` | `order` | default play mode of the audio player options can be set to `order`,`orderLoop`,`singleLoop`,`shufflePlay` or omitted |
|
|
149
|
-
| mode | `string` | `mini` | audio theme switch checkedText can be set to `mini`,`full` or omitted |
|
|
150
|
-
| once | `boolean` | `false` | The default audioPlay handle function will be played again after each pause, If you only want to trigger it once, you can set 'true' |
|
|
151
|
-
| autoPlay | `boolean` | `true` | Whether the audio is played after loading is completed. mobile devices are invalid [autoplay-policy-changes](https://developers.google.com/web/updates/2017/09/autoplay-policy-changes) |
|
|
152
|
-
| toggleMode | `boolean` | `true` | Whether you can switch between two modes, full => mini or mini => full |
|
|
153
|
-
| drag | `boolean` | `true` | audio controller is can be drag of the "mini" mode |
|
|
154
|
-
| seeked | `boolean` | `true` | Whether you can drag or click the progress bar to play in the new progress. |
|
|
155
|
-
| showMiniModeCover | `boolean` | `true` | audio cover is show of the "mini" mode |
|
|
156
|
-
| showMiniProcessBar | `boolean` | `false` | audio progress circle bar is show of the "mini" mode |
|
|
157
|
-
| showProgressLoadBar | `boolean` | `true` | Displays the audio load progress bar. |
|
|
158
|
-
| showPlay | `boolean` | `true` | play button display of the audio player panel |
|
|
159
|
-
| showReload | `boolean` | `true` | reload button display of the audio player panel |
|
|
160
|
-
| showDownload | `boolean` | `true` | download button display of the audio player panel |
|
|
161
|
-
| showPlayMode | `boolean` | `true` | play mode toggle button display of the audio player panel |
|
|
162
|
-
| showThemeSwitch | `boolean` | `true` | theme toggle switch display of the audio player panel |
|
|
163
|
-
| showLyric | `boolean` | `false` | audio lyric button display of the audio player panel |
|
|
164
|
-
| showMediaSession | `boolean` | `false` | [https://web.dev/media-session/](https://web.dev/media-session/) |
|
|
165
|
-
| lyricClassName | `string` | `-` | audio lyric class name |
|
|
166
|
-
| extendsContent | `ReactNode \| boolean \| string` | `-` | Extensible custom content like `<><button>button1</button> <button>button2</button></>` |
|
|
167
|
-
| defaultVolume | `number` | `1` | default volume of the audio player , range `0`-`1` |
|
|
168
|
-
| loadAudioErrorPlayNext | `boolean` | `true` | Whether to try playing the next audio when the current audio playback fails |
|
|
169
|
-
| responsive | `boolean` | `true` | Whether to turn on the response mode, if set false, audio controller always show desktop ui |
|
|
170
|
-
| onAudioDownload | `function(audioInfo)` | `-` | audio is downloaded handle |
|
|
171
|
-
| onAudioPlay | `function(audioInfo)` | `-` | audio play handle |
|
|
172
|
-
| onAudioPause | `function(audioInfo)` | `-` | audio pause handle |
|
|
173
|
-
| onAudioSeeked | `function(audioInfo)` | `-` | When the user has moved/jumped to a new location in audio handle |
|
|
174
|
-
| onAudioVolumeChange | `function(volume)` | `-` | When the volume has changed handle min = 0.0 max = 1.0 |
|
|
175
|
-
| onAudioEnded | `function(currentPlayId,audioLists,audioInfo)` | `-` | The single song is ended handle |
|
|
176
|
-
| onAudioAbort | `function(currentPlayId, audioLists, audioInfo)` | `-` | audio load abort The target event like {...,audioName:xx,audioSrc:xx,playMode:xx} |
|
|
177
|
-
| onAudioProgress | `function(audioInfo)` | `-` | audio play progress handle |
|
|
178
|
-
| onAudioError | `function(errMsg,currentPlayId, audioLists, audioInfo)` | `-` | audio load failed error handle |
|
|
179
|
-
| onAudioReload | `function(audioInfo)` | `-` | audio reload handle |
|
|
180
|
-
| onAudioListsChange | `function(currentPlayId,audioLists,audioInfo)` | `-` | audio lists change handle |
|
|
181
|
-
| onAudioPlayTrackChange | `function(currentPlayId,audioLists,audioInfo)` | `-` | audio current play track change handle |
|
|
182
|
-
| onAudioPlayModeChange | `function(playMode)` | `-` | play mode change handle |
|
|
183
|
-
| onAudioListsPanelChange | `function(panelVisible)` | `-` | audio lists panel change handle |
|
|
184
|
-
| onThemeChange | `function(theme)` | `-` | theme change handle |
|
|
185
|
-
| onModeChange | `function(mode)` | `-` | mode change handle |
|
|
186
|
-
| onAudioListsSortEnd | `function(oldIndex,newIndex)` | `-` | audio lists sort end handle, use [SortableJS](https://github.com/SortableJS/Sortable) |
|
|
187
|
-
| onAudioLyricChange | `function(lineNum, currentLyric)` | `-` | audio lyric change handle |
|
|
188
|
-
| getContainer | `() => HTMLElement` \| `Selectors` | `document.body` | Return the mount node for Music player |
|
|
189
|
-
| getAudioInstance | `(instance: HTMLAudioElement) => void` | `-` | get origin audio element instance , you can use it do everything |
|
|
190
|
-
| autoHiddenCover | `boolean` | `false` | Auto hide the cover photo if no cover photo is available |
|
|
191
|
-
| onBeforeAudioDownload | `(audioInfo: ReactJkMusicPlayerAudioInfo) => Promise<TransformedDownloadAudioInfo>` | `-` | transform download audio info before |
|
|
192
|
-
| clearPriorAudioLists | `boolean` | `false` | Replace a new playlist with the first loaded playlist, |
|
|
193
|
-
| autoPlayInitLoadPlayList | `boolean` | `false` | Play your new play list right after your new play list is loaded turn false. |
|
|
194
|
-
| spaceBar | `boolean` | `false` | Play and pause audio through space bar (Desktop effective). |
|
|
195
|
-
| showDestroy | `boolean` | `false` | Destroy player button display |
|
|
196
|
-
| onBeforeDestroy | `function(currentPlayId,audioLists,audioInfo)` | `-` | custom destroy handler before |
|
|
197
|
-
| onDestroyed | `function(currentPlayId,audioLists,audioInfo)` | `-` | player destroyed handle |
|
|
198
|
-
| customDownloader | `function(downloadInfo: TransformedDownloadAudioInfo)` | `-` | custom download handle |
|
|
199
|
-
| onCoverClick | `function(mode,audioLists,audioInfo)` | `-` | audio cover clicked handle |
|
|
200
|
-
| onPlayIndexChange | `function(playIndex)` | `-` | audio play index change handle |
|
|
201
|
-
| quietUpdate | `boolean` | `false` | [Detail](#bulb-quiet-update) |
|
|
202
|
-
| renderAudioTitle | `(audioInfo, isMobile) => ReactNode` | `-` | use `locale.audioTitle` to set `audio` tag title, the api can render custom jsx element for display |
|
|
203
|
-
| mobileMediaQuery | `string` | `(max-width: 768px) and (orientation : portrait)` | custom mobile media query string, eg use the mobile version UI on iPad. <https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries> |
|
|
204
|
-
| volumeFade | `{ fadeIn: number(ms), fadeOut: number(ms) }` | `-` | audio fade in and out. [Detail](#bulb-audio-volume-fade-in-and-fade-out) |
|
|
205
|
-
| sortableOptions | `object` | `{swap: true, animation: 100, swapClass: 'audio-lists-panel-sortable-highlight-bg'}` | [SortableJs Options](https://github.com/SortableJS/Sortable#options) |
|
|
206
|
-
| restartCurrentOnPrev | `boolean` | `false` | Restarts the current track when trying to play previous song, if the current time of the song is more than 1 second |
|
|
207
|
-
|
|
208
|
-
## :bulb: Custom operation ui
|
|
209
|
-
|
|
210
|
-
Support feature:
|
|
211
|
-
|
|
212
|
-
- `play`
|
|
213
|
-
- `pause`
|
|
214
|
-
- `reload`
|
|
215
|
-
- `change play time`
|
|
216
|
-
- `change playback rate`
|
|
217
|
-
- `change volume`
|
|
218
|
-
- `destroy audio player`
|
|
219
|
-
- `toggle play`
|
|
220
|
-
- `clear audio list`
|
|
221
|
-
- `toggle play`
|
|
222
|
-
- `play next audio`
|
|
223
|
-
- `play prev audio`
|
|
224
|
-
- `play audio by custom play index`
|
|
225
|
-
- `update play index`
|
|
226
|
-
- [SortableJS methods](https://github.com/SortableJS/Sortable#methods)
|
|
227
|
-
|
|
228
|
-
```jsx
|
|
229
|
-
class App extends React.Component {
|
|
230
|
-
constructor() {
|
|
231
|
-
this.audioInstance = null
|
|
232
|
-
}
|
|
233
|
-
render() {
|
|
234
|
-
return (
|
|
235
|
-
<>
|
|
236
|
-
<ReactJkMusicPlayer
|
|
237
|
-
getAudioInstance={(instance) => {
|
|
238
|
-
this.audioInstance = instance
|
|
239
|
-
}}
|
|
240
|
-
/>
|
|
241
|
-
<button onClick={() => this.audioInstance.play()}>play</button>
|
|
242
|
-
<button onClick={() => this.audioInstance.pause()}>pause</button>
|
|
243
|
-
<button onClick={() => this.audioInstance.load()}>reload</button>
|
|
244
|
-
<button onClick={() => this.audioInstance.currentTime = 40}>
|
|
245
|
-
change current play time
|
|
246
|
-
</button>
|
|
247
|
-
<button onClick={() => this.audioInstance.playbackRate = 2}>
|
|
248
|
-
change play back rate
|
|
249
|
-
</button>
|
|
250
|
-
<button onClick={() => this.audioInstance.volume = 0.2}>
|
|
251
|
-
change volume
|
|
252
|
-
</button>
|
|
253
|
-
<button onClick={() => this.audioInstance.destroy()}>
|
|
254
|
-
destroy player
|
|
255
|
-
</button>
|
|
256
|
-
<button onClick={this.audio.togglePlay}>toggle play</button>
|
|
257
|
-
<button onClick={this.audio.clear}>clear audio lists</button>
|
|
258
|
-
<button onClick={this.audio.playNext}>play next</button>
|
|
259
|
-
<button onClick={this.audio.playPrev}>play prev</button>
|
|
260
|
-
<button onClick={() => this.audio.playByIndex(1)}>play by index</button>
|
|
261
|
-
<button onClick={() => this.audio.updatePlayIndex(1)}>
|
|
262
|
-
update play index
|
|
263
|
-
</button>
|
|
264
|
-
</>
|
|
265
|
-
)
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
## :bulb: Glass bg
|
|
271
|
-
|
|
272
|
-
```jsx
|
|
273
|
-
<ReactJkMusicPlayer glassBg />
|
|
274
|
-
```
|
|
275
|
-
|
|
276
|
-
<p>
|
|
277
|
-
<img alt="glass-1" src="https://github.com/lijinke666/react-music-player/blob/master/assetsImg/glass-1.png?raw=true" width="200" max-width="49%">
|
|
278
|
-
<img alt="glass-2" src="https://github.com/lijinke666/react-music-player/blob/master/assetsImg/glass-2.png?raw=true" width="200" max-width="49%">
|
|
279
|
-
</p>
|
|
280
|
-
|
|
281
|
-
## :bulb: Custom downloader
|
|
282
|
-
|
|
283
|
-
Default use [downloadjs](https://github.com/rndme/download), you can use any download library
|
|
284
|
-
|
|
285
|
-
eg. <https://www.npmjs.com/package/file-saver>, or use `download` attribute
|
|
286
|
-
|
|
287
|
-
```jsx
|
|
288
|
-
const customDownloader = (downloadInfo) => {
|
|
289
|
-
const link = document.createElement('a')
|
|
290
|
-
link.href = downloadInfo.src // a.mp3
|
|
291
|
-
link.download = downloadInfo.filename || 'test'
|
|
292
|
-
document.body.appendChild(link)
|
|
293
|
-
link.click()
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
;<ReactJkMusicPlayer
|
|
297
|
-
audioLists={[{ src: 'a.mp3' }]}
|
|
298
|
-
customDownloader={customDownloader}
|
|
299
|
-
/>
|
|
300
|
-
|
|
301
|
-
// use onBeforeAudioDownload
|
|
302
|
-
const onBeforeAudioDownload = () => {
|
|
303
|
-
return Promise.resolve({
|
|
304
|
-
src: '1.mp3',
|
|
305
|
-
})
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
const customDownloader = (downloadInfo) => {
|
|
309
|
-
console.log(downloadInfo.src) // 1.mp3
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
;<ReactJkMusicPlayer
|
|
313
|
-
customDownloader={customDownloader}
|
|
314
|
-
onBeforeAudioDownload={onBeforeAudioDownload}
|
|
315
|
-
/>
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
## :bulb: Destroy player
|
|
319
|
-
|
|
320
|
-
```jsx
|
|
321
|
-
const onBeforeDestroy = (currentPlayId, audioLists, audioInfo) => {
|
|
322
|
-
return new Promise((resolve, reject) => {
|
|
323
|
-
// your custom validate
|
|
324
|
-
if (window.confirm('Are you confirm destroy the player?')) {
|
|
325
|
-
// if resolve, player destroyed
|
|
326
|
-
resolve()
|
|
327
|
-
} else {
|
|
328
|
-
// if reject, skip.
|
|
329
|
-
reject()
|
|
330
|
-
}
|
|
331
|
-
})
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
const onDestroyed = (currentPlayId, audioLists, audioInfo) => {
|
|
335
|
-
console.log('onDestroyed:', currentPlayId, audioLists, audioInfo)
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
;<ReactJkMusicPlayer
|
|
339
|
-
showDestroy
|
|
340
|
-
onBeforeDestroy={onBeforeDestroy}
|
|
341
|
-
onDestroyed={onDestroyed}
|
|
342
|
-
/>
|
|
343
|
-
```
|
|
344
|
-
|
|
345
|
-
## :bulb: Media session
|
|
346
|
-
|
|
347
|
-
> <https://web.dev/media-session/>
|
|
348
|
-
|
|
349
|
-
```jsx
|
|
350
|
-
// so cool, so easy !!!
|
|
351
|
-
<ReactJkMusicPlayer showMediaSession />
|
|
352
|
-
```
|
|
353
|
-
|
|
354
|
-
<img src="https://github.com/lijinke666/react-music-player/blob/master/assetsImg/media-session-destop.png" max-width="100%"/>
|
|
355
|
-
<img src="https://github.com/lijinke666/react-music-player/blob/master/assetsImg/media-session-mobile.jpeg" width="400" max-width="100%"/>
|
|
356
|
-
|
|
357
|
-
## :bulb: Internationalization
|
|
358
|
-
|
|
359
|
-
> Version: 4.11.0
|
|
360
|
-
|
|
361
|
-
[Source](https://github.com/lijinke666/react-music-player/blob/master/src/locale/index.js)
|
|
362
|
-
|
|
363
|
-
```jsx
|
|
364
|
-
import Locale from 'react-jinke-music-player/lib/config/locale'
|
|
365
|
-
// Two languages are provided by default
|
|
366
|
-
// one of zh_CN | en_US
|
|
367
|
-
<ReactJkMusicPlayer locale={Locale.zh_CN}/>
|
|
368
|
-
// <ReactJkMusicPlayer locale={'en_US'}/>
|
|
369
|
-
|
|
370
|
-
// Custom override
|
|
371
|
-
const customLocale = {
|
|
372
|
-
playModeText: {
|
|
373
|
-
order: '',
|
|
374
|
-
orderLoop: '',
|
|
375
|
-
singleLoop: '',
|
|
376
|
-
shufflePlay: ''
|
|
377
|
-
},
|
|
378
|
-
openText: '',
|
|
379
|
-
closeText: '',
|
|
380
|
-
emptyText: '',
|
|
381
|
-
clickToPlayText: '',
|
|
382
|
-
clickToPauseText: '',
|
|
383
|
-
nextTrackText: '',
|
|
384
|
-
previousTrackText: '',
|
|
385
|
-
reloadText: '',
|
|
386
|
-
volumeText: '',
|
|
387
|
-
playListsText: '',
|
|
388
|
-
toggleLyricText: '',
|
|
389
|
-
toggleMiniModeText: '',
|
|
390
|
-
destroyText: '',
|
|
391
|
-
downloadText: '',
|
|
392
|
-
lightThemeText: '',
|
|
393
|
-
darkThemeText: '',
|
|
394
|
-
switchThemeText: '',
|
|
395
|
-
removeAudioListsText: '',
|
|
396
|
-
controllerTitle: '',
|
|
397
|
-
emptyLyricText: '',
|
|
398
|
-
clickToDeleteText: (name) => ``,
|
|
399
|
-
audioTitle: ''
|
|
400
|
-
// audioTitle: (audioInfo) => ``
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
<ReactJkMusicPlayer locale={customLocale}/>
|
|
404
|
-
|
|
405
|
-
// Support partial override, auto merge
|
|
406
|
-
|
|
407
|
-
<ReactJkMusicPlayer locale={{ audioTitle: "xxx" }}/>
|
|
408
|
-
```
|
|
409
|
-
|
|
410
|
-
## :bulb: Customize Theme
|
|
411
|
-
|
|
412
|
-
```jsx
|
|
413
|
-
import ReactJkMusicPlayer from 'react-jinke-music-player'
|
|
414
|
-
import 'react-jinke-music-player/lib/styles/index.less'
|
|
415
|
-
```
|
|
416
|
-
|
|
417
|
-
```less
|
|
418
|
-
@primary-color: #31c27c;
|
|
419
|
-
@default-color: #d9d9d9;
|
|
420
|
-
@bg-color: #f7f8fa;
|
|
421
|
-
@border-color: #d9d9d9;
|
|
422
|
-
@panel-bg-light: #fff;
|
|
423
|
-
@controller-bg-light: #fff;
|
|
424
|
-
@music-player-panel-height: 80px;
|
|
425
|
-
@lists-panel-width: 480px;
|
|
426
|
-
@lists-panel-height: 410px;
|
|
427
|
-
@lists-panel-item-bg: #40444b;
|
|
428
|
-
@lists-panel-item-bg-light: #fff;
|
|
429
|
-
@panel-header-height: 50px;
|
|
430
|
-
@panel-bg: rgba(0, 0, 0, 0.7);
|
|
431
|
-
@font-color: #444;
|
|
432
|
-
@player-width: 80px;
|
|
433
|
-
@player-height: @player-width;
|
|
434
|
-
@base-color: rgba(255, 255, 255, 0.6);
|
|
435
|
-
@common-animate-type: cubic-bezier(0.43, -0.1, 0.16, 1.1);
|
|
436
|
-
@common-animate-time: 350ms @common-animate-type;
|
|
437
|
-
@progress-load-bar-bg-color: rgba(0, 0, 0, 0.11);
|
|
438
|
-
@progress-load-bar-bg-color-light: rgba(0, 0, 0, 0.06);
|
|
439
|
-
@progress-bar-bg-color-light: rgba(0, 0, 0, 0.09);
|
|
440
|
-
@progress-bar-bg-color-dark: #fff;
|
|
441
|
-
@player-lyric-color: @primary-color;
|
|
442
|
-
@player-lyric-font-size: 36px;
|
|
443
|
-
@player-lyric-font-size-mobile: 16px;
|
|
444
|
-
@player-lyric-z-index: 999;
|
|
445
|
-
```
|
|
446
|
-
|
|
447
|
-
> Customize in webpack
|
|
448
|
-
|
|
449
|
-
```diff
|
|
450
|
-
// webpack.config.js
|
|
451
|
-
|
|
452
|
-
module.exports = {
|
|
453
|
-
rules: [{
|
|
454
|
-
test: /\.less$/,
|
|
455
|
-
use: [
|
|
456
|
-
...
|
|
457
|
-
{
|
|
458
|
-
loader: 'less-loader',
|
|
459
|
-
+ options: {
|
|
460
|
-
+ modifyVars: {
|
|
461
|
-
+ 'primary-color': '#444',
|
|
462
|
-
+ // or
|
|
463
|
-
+ 'hack': `true; @import "your-less-file-path.less";`, // Override with less file
|
|
464
|
-
+ },
|
|
465
|
-
+ javascriptEnabled: true,
|
|
466
|
-
+ },
|
|
467
|
-
}],
|
|
468
|
-
}],
|
|
469
|
-
}
|
|
470
|
-
```
|
|
471
|
-
|
|
472
|
-
> Customize in less file
|
|
473
|
-
|
|
474
|
-
```less
|
|
475
|
-
@import 'react-jinke-music-player/lib/styles/index.less';
|
|
476
|
-
@import 'your-theme-file.less';
|
|
477
|
-
```
|
|
478
|
-
|
|
479
|
-
## :bulb: Customize audio duration
|
|
480
|
-
|
|
481
|
-
> Default: by this.audio.duration, if cannot get current play audio's duration, you can customize to set.
|
|
482
|
-
|
|
483
|
-
```jsx
|
|
484
|
-
<ReactJkMusicPlayer audioLists={[{
|
|
485
|
-
...
|
|
486
|
-
duration: 100.00
|
|
487
|
-
}]} />
|
|
488
|
-
|
|
489
|
-
```
|
|
490
|
-
|
|
491
|
-
## :bulb: Customize player icon
|
|
492
|
-
|
|
493
|
-
```ts
|
|
494
|
-
export interface ReactJkMusicPlayerIcon {
|
|
495
|
-
pause?: React.ReactNode | string
|
|
496
|
-
play?: React.ReactNode | string
|
|
497
|
-
destroy?: React.ReactNode | string
|
|
498
|
-
close?: React.ReactNode | string
|
|
499
|
-
delete?: React.ReactNode | string
|
|
500
|
-
download?: React.ReactNode | string
|
|
501
|
-
toggle?: React.ReactNode | string
|
|
502
|
-
lyric?: React.ReactNode | string
|
|
503
|
-
volume?: React.ReactNode | string
|
|
504
|
-
mute?: React.ReactNode | string
|
|
505
|
-
next?: React.ReactNode | string
|
|
506
|
-
prev?: React.ReactNode | string
|
|
507
|
-
playLists?: React.ReactNode | string
|
|
508
|
-
reload?: React.ReactNode | string
|
|
509
|
-
loop?: React.ReactNode | string
|
|
510
|
-
order?: React.ReactNode | string
|
|
511
|
-
orderLoop?: React.ReactNode | string
|
|
512
|
-
shuffle?: React.ReactNode | string
|
|
513
|
-
loading?: React.ReactNode | string
|
|
514
|
-
}
|
|
515
|
-
```
|
|
516
|
-
|
|
517
|
-
## :bulb: Follow the theme of the system
|
|
518
|
-
|
|
519
|
-
```jsx
|
|
520
|
-
<ReactJkMusicPlayer theme="auto" />
|
|
521
|
-
```
|
|
522
|
-
|
|
523
|
-

|
|
524
|
-
|
|
525
|
-
## :bulb: Quiet update
|
|
526
|
-
|
|
527
|
-
```jsx
|
|
528
|
-
/**
|
|
529
|
-
* Don't interrupt current playing state when audio list updated
|
|
530
|
-
* eg. (A) is current playing...
|
|
531
|
-
* [A,B] => [A,C,B]
|
|
532
|
-
* [A,B] => [A,B,C]
|
|
533
|
-
*
|
|
534
|
-
* if (A) not in updated audio lists
|
|
535
|
-
* [A,B] => [C]
|
|
536
|
-
* (C) is playing
|
|
537
|
-
*/
|
|
538
|
-
|
|
539
|
-
function App() {
|
|
540
|
-
const [audioLists, setAudioLists] = useState([
|
|
541
|
-
{ musicSrc: 'A' },
|
|
542
|
-
{ musicSrc: 'B' },
|
|
543
|
-
])
|
|
544
|
-
|
|
545
|
-
useEffect(() => {
|
|
546
|
-
setTimeout(() => {
|
|
547
|
-
setAudioLists([{ musicSrc: 'A' }, { musicSrc: 'C' }, { musicSrc: 'B' }])
|
|
548
|
-
}, 1000)
|
|
549
|
-
}, [setAudioLists])
|
|
550
|
-
|
|
551
|
-
return (
|
|
552
|
-
<ReactJkMusicPlayer
|
|
553
|
-
quietUpdate
|
|
554
|
-
clearPriorAudioLists
|
|
555
|
-
audioLists={audioLists}
|
|
556
|
-
/>
|
|
557
|
-
)
|
|
558
|
-
}
|
|
559
|
-
```
|
|
560
|
-
|
|
561
|
-
## :bulb: Import in browser
|
|
562
|
-
|
|
563
|
-
```html
|
|
564
|
-
<!DOCTYPE html>
|
|
565
|
-
<html lang="en">
|
|
566
|
-
<head>
|
|
567
|
-
<link
|
|
568
|
-
rel="stylesheet"
|
|
569
|
-
href="https://unpkg.com/react-jinke-music-player@4.18.1/assets/index.css"
|
|
570
|
-
/>
|
|
571
|
-
</head>
|
|
572
|
-
<body>
|
|
573
|
-
<div id="root"></div>
|
|
574
|
-
</body>
|
|
575
|
-
<script src="https://unpkg.com/react@16.13.1/umd/react.production.min.js"></script>
|
|
576
|
-
<script src="https://unpkg.com/react-dom@16.13.1/umd/react-dom.production.min.js"></script>
|
|
577
|
-
<script src="https://unpkg.com/react-jinke-music-player@4.18.1/dist/react-jinke-music-player.min.js"></script>
|
|
578
|
-
<script>
|
|
579
|
-
ReactDOM.render(
|
|
580
|
-
React.createElement(ReactJkMusicPlayer),
|
|
581
|
-
document.getElementById('root'),
|
|
582
|
-
)
|
|
583
|
-
</script>
|
|
584
|
-
</html>
|
|
585
|
-
```
|
|
586
|
-
|
|
587
|
-
## :bulb: Server-Side Rendering
|
|
588
|
-
|
|
589
|
-
```jsx
|
|
590
|
-
// components/Player.js
|
|
591
|
-
import React from 'react'
|
|
592
|
-
import ReactJkMusicPlayer from 'react-jinke-music-player'
|
|
593
|
-
import styles from 'react-jinke-music-player/assets/index.module.css'
|
|
594
|
-
|
|
595
|
-
export const Player = () => <ReactJkMusicPlayer />
|
|
596
|
-
|
|
597
|
-
// pages/_app.js
|
|
598
|
-
import dynamic from 'next/dynamic'
|
|
599
|
-
const PlayerWithNoSSR = dynamic(() => import('../components/Player'), {
|
|
600
|
-
ssr: false,
|
|
601
|
-
})
|
|
602
|
-
```
|
|
603
|
-
|
|
604
|
-
## :bulb: Customize mobile media query
|
|
605
|
-
|
|
606
|
-
> eg. Use mobile UI on a iPad device
|
|
607
|
-
|
|
608
|
-
```jsx
|
|
609
|
-
// Default '(max-width: 768px) and (orientation : portrait)'
|
|
610
|
-
<ReactJkMusicPlayer mobileMediaQuery="(max-width: 1024px)" />
|
|
611
|
-
```
|
|
612
|
-
|
|
613
|
-
## :bulb: Audio volume fade in and fade out
|
|
614
|
-
|
|
615
|
-
```jsx
|
|
616
|
-
<ReactJkMusicPlayer volumeFade={{ fadeIn: 500, fadeOut: 500 }} />
|
|
617
|
-
```
|
|
618
|
-
|
|
619
|
-
## :pencil: Development
|
|
620
|
-
|
|
621
|
-
```bash
|
|
622
|
-
git clone https://github.com/lijinke666/react-music-player.git
|
|
623
|
-
yarn # npm install
|
|
624
|
-
yarn start # npm start
|
|
625
|
-
open `http://localhost:8084/`
|
|
626
|
-
```
|
|
627
|
-
|
|
628
|
-
## :hourglass: Test case
|
|
629
|
-
|
|
630
|
-
```bash
|
|
631
|
-
npm run test
|
|
632
|
-
```
|
|
633
|
-
|
|
634
|
-
## :bulb: AudioListProps
|
|
635
|
-
|
|
636
|
-
> Like This
|
|
637
|
-
|
|
638
|
-
```ts
|
|
639
|
-
interface ReactJkMusicPlayerAudioListProps {
|
|
640
|
-
name: string | React.ReactNode,
|
|
641
|
-
musicSrc: string | () => Promise<string>,
|
|
642
|
-
cover: string,
|
|
643
|
-
singer?: string | React.ReactNode,
|
|
644
|
-
duration?: number,
|
|
645
|
-
lyric?: string,
|
|
646
|
-
[key: string]: any
|
|
647
|
-
}>
|
|
648
|
-
```
|
|
649
|
-
|
|
650
|
-
## :bulb: AudioInfo
|
|
651
|
-
|
|
652
|
-
> Like This
|
|
653
|
-
|
|
654
|
-
```ts
|
|
655
|
-
interface ReactJkMusicPlayerAudioInfo {
|
|
656
|
-
cover: string
|
|
657
|
-
currentTime: number
|
|
658
|
-
duration: number
|
|
659
|
-
ended: boolean
|
|
660
|
-
musicSrc: string
|
|
661
|
-
muted: boolean
|
|
662
|
-
name: string
|
|
663
|
-
networkState: number
|
|
664
|
-
paused: boolean
|
|
665
|
-
played: any
|
|
666
|
-
readyState: number
|
|
667
|
-
startDate: any
|
|
668
|
-
volume: number
|
|
669
|
-
lyric: string
|
|
670
|
-
[key: string]: any
|
|
671
|
-
}
|
|
672
|
-
```
|
|
673
|
-
|
|
674
|
-
## :two_men_holding_hands: Contributors
|
|
675
|
-
|
|
676
|
-
> Special thanks: @JeffreyCA
|
|
677
|
-
|
|
678
|
-

|
|
679
|
-
|
|
680
|
-
## :page_facing_up: License
|
|
681
|
-
|
|
682
|
-
[MIT](https://github.com/lijinke666/react-music-player/blob/master/LICENCE)
|
|
6
|
+
This fork won't be maintained and will be most probably replaced by a different
|
|
7
|
+
player in the future.
|