Skip to content

Commit

Permalink
feat: appendAudio method deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 committed Mar 16, 2021
1 parent 06fb15c commit 8009865
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 127 deletions.
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ ReactDOM.render(
| renderAudioTitle | `(audioInfo, isMobile) => ReactNode` | `-` | use `locale.audioTitle` to set `audio` tag title, the api can render custom jsx element for display |
| 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> |
| volumeFade | `{ fadeIn: number(ms), fadeOut: number(ms) }` | `-` | audio fade in and out. [Detail](#bulb-audio-volume-fade-in-and-fade-out) |
| sortableOptions | `{ fadeIn: number(ms), fadeOut: number(ms) }` | `{swap: true, animation: 100, swapClass: 'audio-lists-panel-sortable-highlight-bg'}` | [SortableJs Options](https://github.com/SortableJS/Sortable#options) |
| sortableOptions | `object` | `{swap: true, animation: 100, swapClass: 'audio-lists-panel-sortable-highlight-bg'}` | [SortableJs Options](https://github.com/SortableJS/Sortable#options) |

## :bulb: Custom operation ui

Expand All @@ -215,7 +215,6 @@ Support feature:
- `change playback rate`
- `change volume`
- `destroy audio player`
- `append some audio to current audio lists`
- `toggle play`
- `clear audio list`
- `toggle play`
Expand Down Expand Up @@ -253,13 +252,6 @@ class App extends React.Component {
<button onClick={() => this.audioInstance.destroy()}>
destroy player
</button>
<button
onClick={() =>
this.audio.appendAudio(1, [{ musicSrc: 'x', name: 'xx', singer: 'xx }])
}
>
append audio
</button>
<button onClick={this.audio.togglePlay}>toggle play</button>
<button onClick={this.audio.clear}>clear audio lists</button>
<button onClick={this.audio.playNext}>play next</button>
Expand Down
80 changes: 1 addition & 79 deletions __tests__/tests/instance.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ describe('AudioInstance test', () => {
'playPrev',
'playNext',
'togglePlay',
'clear',
'appendAudio'),
'clear'),
].forEach((key) => {
expect(instance[key]).toBeInstanceOf(Function)
})
Expand Down Expand Up @@ -154,81 +153,4 @@ describe('AudioInstance test', () => {
expect(wrapper.state().musicSrc).toEqual('')
expect(wrapper.state().name).toEqual('')
})

it('should appendAudio', async () => {
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {})
const onAudioListsChange = jest.fn()
const { instance, wrapper } = getApp({
onAudioListsChange,
})
instance.appendAudio()
expect(errorSpy).toHaveBeenCalledWith(
'Warning! function appendAudio(){} must have formIndex!',
)
errorSpy.mockClear()
instance.appendAudio(0, [
{
musicSrc: 'c',
},
{
musicSrc: 'd',
},
])
await sleep(300)
expect(onAudioListsChange).toHaveBeenCalled()
expect(wrapper.state().audioLists.map(({ musicSrc }) => musicSrc)).toEqual([
'c',
'd',
'a',
'b',
])
})

it('should set audio info when append audio list', async () => {
const { instance, wrapper } = getApp()
const audioInfo = {
name: 'a',
singer: 'a',
musicSrc: 'c',
}
instance.appendAudio(0, [audioInfo])
await sleep(300)
expect(wrapper.state().name).toEqual(audioInfo.name)
expect(wrapper.state().musicSrc).toEqual(audioInfo.musicSrc)
expect(wrapper.state().singer).toEqual(audioInfo.singer)
})

it('should init append audio info', async () => {
const onAudioPlay = jest.fn()
const { wrapper, instance } = getApp({
mode: 'full',
autoplayInitLoadPlayList: false,
onAudioPlay,
})
const audioInfo = {
name: 'name',
singer: 'singer',
musicSrc: 'c',
}
const prePlayId = wrapper.state().playId
instance.appendAudio(0, [audioInfo])
await sleep(1000)
wrapper.update()
expect(onAudioPlay).not.toHaveBeenCalled()
expect(wrapper.state().loading).toBeFalsy()
expect(wrapper.state().musicSrc).toEqual(audioInfo.musicSrc)
expect(wrapper.state().singer).toEqual(audioInfo.singer)
expect(wrapper.state().name).toEqual(audioInfo.name)
expect(prePlayId).not.toEqual(wrapper.state().audioLists[0].__PLAYER_KEY__)
expect(wrapper.state().playId).toEqual(
wrapper.state().audioLists[0].__PLAYER_KEY__,
)
wrapper.find('.audio-lists-btn').simulate('click')
expect(
wrapper
.find('.audio-lists-panel-content .audio-item')
.first()
.find(AnimatePlayIcon),
).toHaveLength(1)
})
})
14 changes: 0 additions & 14 deletions example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,20 +666,6 @@ class Demo extends React.PureComponent {
>
destroy player
</button>
<button
type="button"
onClick={() => {
this.audio.appendAudio(0, [
{
name: 'test',
musicSrc:
'http://podcasts.protocol-radio.com/podcast/protocol-radio-331.m4a',
},
])
}}
>
append audio
</button>
<button type="button" onClick={this.audio.togglePlay}>
toggle play
</button>
Expand Down
4 changes: 0 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ export interface ReactJkMusicPlayerInstance extends HTMLAudioElement {
playPrev?: () => void
togglePlay?: () => void
clear?: () => void
appendAudio?: (
fromIndex: number,
audioLists: ReactJkMusicPlayerAudioListProps[],
) => void
sortable?: any
}

Expand Down
21 changes: 0 additions & 21 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2137,23 +2137,6 @@ export default class ReactJkMusicPlayer extends PureComponent {
this.updatePlayIndex(index)
}

appendAudio = (fromIndex, audioLists = []) => {
if (!fromIndex && fromIndex !== 0) {
// eslint-disable-next-line no-console
console.error('Warning! function appendAudio(){} must have formIndex!')
return
}
const newAudioLists = [...this.state.audioLists]
const addedAudioLists = audioLists.map((audioInfo) => {
return {
[PLAYER_KEY]: uuId(),
...audioInfo,
}
})
newAudioLists.splice(fromIndex, 0, ...addedAudioLists)
this.changeAudioLists({ ...this.props, audioLists: newAudioLists })
}

getEnhanceAudio = () => {
const { audio } = this
;[
Expand Down Expand Up @@ -2185,10 +2168,6 @@ export default class ReactJkMusicPlayer extends PureComponent {
name: 'clear',
value: this.clearAudioLists,
},
{
name: 'appendAudio',
value: this.appendAudio,
},
{
name: 'sortable',
value: this.sortable,
Expand Down

0 comments on commit 8009865

Please sign in to comment.