2.4.5 • Published 2 months ago

aplayer-ts v2.4.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

Wow, such a lovely HTML5 music player

Fully ESM version of APlayer with TypeScript support. With Rollup and esbuild, index.min.js is 50% smaller than the original APlayer.min.js, from 58KB to less than 30KB.

Why this

See this blog post.

  1. TypeScript
  2. ESM (APlayer only exports APlayer.min.js, which is not friendly to code optimization)
  3. Tree-Shaking, see API difference
    # only import APlayer constructor
    demo_build/index.html                  1.95 kB │ gzip: 0.79 kB
    demo_build/assets/index-3p8iLQ3k.css  10.22 kB │ gzip: 2.19 kB
    demo_build/assets/index-DDEVMoCF.js   27.37 kB │ gzip: 8.66 kB
    # import everything
    demo_build/index.html                  1.95 kB │ gzip: 0.79 kB
    demo_build/assets/index-Bi0rxlmU.css  12.04 kB │ gzip: 2.47 kB
    demo_build/assets/index-CTXYaVj8.js   30.44 kB │ gzip: 9.23 kB

APlayer.min.js is still in dist folder, but by default this package exports src/js/index.js.

It also includes a patch which fixes APlayer#283.

Usage

Basic usage:

import APlayer from 'aplayer-ts'
import 'aplayer-ts/src/css/base.css'

const instance = APlayer()
    .init({ /* refer to the aplayer doc */ })

API difference

  1. fixed option is removed, use APlayerFixedModePlugin instead.
import APlayer, { APlayerFixedModePlugin } from 'aplayer-ts'
import 'aplayer-ts/src/css/base.css'
import 'aplayer-ts/src/css/fixed.css' // remember to import the css

const instance = APlayer()
    .use(APlayerFixedModePlugin)
    .init({ /* refer to the aplayer doc */ })
  1. list.add, list.remove and list.clear are by default removed, install their plugins if you want to use:
import APlayer, { addMusicPlugin, removeMusicPlugin, clearMusicPlugin } from 'aplayer-ts'
import 'aplayer-ts/src/css/base.css'

const instance = APlayer()
    .use(addMusicPlugin)
    .use(removeMusicPlugin)
    .init({ /* refer to the aplayer doc */ })

instance.list.add({ /* new audios here */ })
  1. HLS is by default removed, install APlayerHlsPlugin if you want to use:
import APlayer, { APlayerHlsPlugin } from 'aplayer-ts'
import 'aplayer-ts/src/css/base.css'

const instance = APlayer()
    .use(APlayerHlsPlugin)
    .init({ /* refer to the aplayer doc */ })

Development

Demo website:

pnpm dev         # start a dev server
pnpm build:demo  # build the demo website (to see output size)

Package build:

pnpm build       # ./build/index.{min}.js

APlayer relies on Webpack to import svg and art-template files. This package has already transformed these files into JavaScript code (see utils), so you don't need to worry about the compatibility of your bundler.

2.4.1

2 months ago

2.4.3

2 months ago

2.4.2

2 months ago

2.4.5

2 months ago

2.4.4

2 months ago

2.4.0

2 months ago

2.3.1

2 months ago

2.3.0

2 months ago

2.2.1

2 months ago

2.2.0

2 months ago

2.1.0

2 months ago

1.10.1-10

2 months ago

2.0.1

2 months ago

2.0.0

2 months ago

1.10.1-8

2 months ago

1.10.1-9

2 months ago

1.10.1-4

2 months ago

1.10.1-5

2 months ago

1.10.1-6

2 months ago

1.10.1-7

2 months ago

1.10.1-3

3 months ago

1.10.1-2

3 months ago

1.10.1-0

3 months ago

1.10.1-1

3 months ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago