https://github.com/uk0/wasm-play-mp3
自动播放音乐,无需点击。 Automatically play music without clicking. JavaScript + Html
https://github.com/uk0/wasm-play-mp3
Last synced: 3 months ago
JSON representation
自动播放音乐,无需点击。 Automatically play music without clicking. JavaScript + Html
- Host: GitHub
- URL: https://github.com/uk0/wasm-play-mp3
- Owner: uk0
- Created: 2021-11-22T02:35:41.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-11-22T02:54:39.000Z (over 3 years ago)
- Last Synced: 2025-02-24T16:14:33.084Z (3 months ago)
- Language: C
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# wasm-play-mp3
自动播放音乐,无需点击。 Automatically play music without clicking. JavaScript + Html### wasm 相关代码来自
https://ntzyz.io/post/decode-mpeg-layer-3-using-web-assembly-in-browser
### 感谢
https://github.com/ntzyz
### build
#### 安装emsdk
```bash
# Get the emsdk repo
git clone https://github.com/emscripten-core/emsdk.git# Enter that directory
cd emsdk
# Fetch the latest version of the emsdk (not needed the first time you clone)
git pull# Download and install the latest SDK tools.
./emsdk install latest# Make the "latest" SDK "active" for the current user. (writes .emscripten file)
./emsdk activate latest# Activate PATH and other environment variables in the current terminal
source ./emsdk_env.sh# use gcc8 g++8
./emsdk install sdk-upstream-main-64bit
./emsdk install binaryen-main-64bit./emsdk activate sdk-upstream-main-64bit
./emsdk activate binaryen-main-64bit```
#### 安装libmad
* 1. 下载 libmad https://sourceforge.net/projects/mad/files/libmad/0.15.1b/libmad-0.15.1b.tar.gz/download
* 2. source ./emsdk_env.sh```bash
cd /path/to/libmad.tar.gz/
tar xzf libmad*.tar.gz
cd libmad*
mkdir ../build
emconfigure ./configure --prefix=$(pwd)/../build
emmake make
emmake make install
```#### build-wasm
* 1. wasm 环境 X86_64 切换标识 `#define X86_64` wasm 下记得注释掉
```bash
# main.c 在这个build 文件夹下
mkdir server
emcc -I../build/include -L../build/lib main.c -lmad -s WASM=1 -o server/test.html -s TOTAL_MEMORY=268435456 -s EXPORTED_FUNCTIONS="['_main','_malloc', '_decode_mp3_to_pcm']" -s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall","cwrap","writeArrayToMemory"]' -O3```
#### 查看文件目录
```bash
root@DESKTOP-PFF8EKP:/mnt/f/emsdk/build# tree .
.
├── include
│ └── mad.h
├── lib
│ ├── libmad.a
│ ├── libmad.la
│ ├── libmad.so -> libmad.so.0.2.1
│ ├── libmad.so.0 -> libmad.so.0.2.1
│ └── libmad.so.0.2.1
├── main.c
└── server
├── test.html
├── test.js
└── test.wasm
```