feat(web): new look, part 2: the player with a live spectrogram
- A spectrogram drawn in the browser from the sound being played: the last seconds, time running to the right and ending now, low notes at the bottom, brighter where there is more energy. Small in the player bar, large in the full-screen player. It works the same for a friend's track, since its audio comes through this server. - It is drawn only while something plays and the page is in view, and with reduced motion it is redrawn four times a second; where the browser has no Web Audio it stays empty and nothing else changes. - The play button is round, in the colour of this server and in the friend colour for a friend's track. - The bar and the full-screen player show the name of the friend whose server a track comes from, and nothing for this server's own music.
This commit is contained in:
parent
adc3aa2832
commit
fdf1ebfabc
1 changed files with 417 additions and 20 deletions
27
web/src/components/Spectrogram.test.tsx
Normal file
27
web/src/components/Spectrogram.test.tsx
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { render, screen } from '@testing-library/react'
|
||||
import { beforeEach, expect, test, vi } from 'vitest'
|
||||
import { initI18n } from '@/i18n'
|
||||
import Spectrogram from './Spectrogram'
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.spyOn(navigator, 'language', 'get').mockReturnValue('en-US')
|
||||
await initI18n()
|
||||
})
|
||||
|
||||
test('it is a picture with a name, and a canvas where the browser can draw', () => {
|
||||
render(<Spectrogram className="h-10 w-40" />)
|
||||
const picture = screen.getByRole('img', { name: 'Spectrogram of what is playing' })
|
||||
expect(picture.querySelector('canvas')).not.toBeNull()
|
||||
})
|
||||
|
||||
test('where the browser has no Web Audio it draws nothing and breaks nothing', () => {
|
||||
vi.stubGlobal('AudioContext', undefined)
|
||||
expect(() => render(<Spectrogram className="h-10 w-40" />)).not.toThrow()
|
||||
})
|
||||
|
||||
test('it takes the colour of this server, or of a friend', () => {
|
||||
const { rerender } = render(<Spectrogram />)
|
||||
expect(screen.getByRole('img').className).toContain('text-primary')
|
||||
rerender(<Spectrogram friend />)
|
||||
expect(screen.getByRole('img').className).toContain('text-friend')
|
||||
})
|
||||
Loading…
Reference in a new issue