Skip to content

Commit 9198eca

Browse files
Merge pull request #50 from The-Infinitys/Article-about-musicsection
Create article.md
2 parents 32da4e4 + dbcc3a4 commit 9198eca

File tree

5 files changed

+230
-1
lines changed

5 files changed

+230
-1
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
---
2+
title: Music Player Now Available!
3+
date: "2025-06-14"
4+
description: "Been wrestling with bugs non-stop (´・ω・`)"
5+
---
6+
7+
# Section of Music
8+
9+
Hi there! This is The Infinity's!
10+
11+
I create music as a hobby, and today I'm excited to announce that I've built a dedicated page to share my music with you all!
12+
13+
## Key Features
14+
15+
Our music player comes with the following features:
16+
17+
1. Basic Playback Controls
18+
- Play/Pause
19+
- Track seeking
20+
- Fast forward/Rewind
21+
- Next/Previous track navigation
22+
23+
2. Playback Speed Control
24+
- Adjustable from 0.5x to 2x speed
25+
26+
3. Equalizer Function
27+
- 5-band equalizer
28+
- Multiple presets
29+
- Custom settings available
30+
31+
4. Visualizer
32+
- Toggle between linear and circular display
33+
- Real-time audio waveform visualization
34+
35+
## Technical Implementation Details
36+
37+
### Audio Processing Implementation
38+
39+
```tsx
40+
const audioCtxRef = useRef<AudioContext | null>(null);
41+
const elementSource = audioCtxRef.current.createMediaElementSource(
42+
audioRef.current
43+
);
44+
```
45+
46+
We're utilizing the Web Audio API to create an audio context, which enables us to process and analyze audio signals.
47+
48+
### Equalizer Implementation
49+
50+
```tsx
51+
const eqFilters: BiquadFilterNode[] = [
52+
audioCtxRef.current.createBiquadFilter(),
53+
// ...
54+
];
55+
56+
const frequencies = [60, 250, 1000, 4000, 16000];
57+
```
58+
59+
The equalizer employs BiquadFilterNodes for each of the five frequency bands (from bass to treble).
60+
Each filter is assigned a specific center frequency and can be adjusted using the gain parameter.
61+
62+
### Visualizer Rendering
63+
64+
```tsx
65+
const renderFrame = () => {
66+
analyserNode.getByteFrequencyData(dataArray);
67+
// ...
68+
animationFrameRef.current = requestAnimationFrame(renderFrame);
69+
};
70+
```
71+
72+
We're using an AnalyserNode to analyze audio data in real-time and rendering the waveform using the Canvas API.
73+
The requestAnimationFrame ensures smooth animation performance.
74+
75+
### Playback Control Implementation
76+
77+
```tsx
78+
const handleTogglePlay = () => {
79+
if (!audioRef.current || !audioCtxRef.current) return;
80+
81+
if (audioCtxRef.current.state === "suspended") {
82+
audioCtxRef.current.resume();
83+
setPlayState("play");
84+
}
85+
// ...
86+
};
87+
```
88+
89+
The playback control combines HTMLAudioElement and AudioContext to manage audio playback.
90+
State management is handled appropriately based on user interactions.
91+
92+
### Playlist Functionality
93+
94+
```tsx
95+
const handleNextTrack = () => {
96+
if (!musicList || musicList.length === 0) return;
97+
const nextId = getNextTrackId();
98+
window.location.href = `/music/${nextId}`;
99+
};
100+
```
101+
102+
The playlist system determines the next or previous track based on the current track index
103+
and handles navigation to the appropriate URL.
104+
105+
## Conclusion
106+
107+
By combining the Web Audio API and Canvas API, we've successfully created a full-featured music player in the browser.
108+
While implementing the equalizer and visualizer presented some challenges,
109+
we're pleased with the result - a user-friendly player with advanced audio playback capabilities!
110+
111+
While there's always room for improvement, we're happy to have completed these core features.
112+
In future updates, we plan to add more user-friendly features like playlist saving and shuffle play functionality!
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
---
2+
title: 音楽が聴けるようになりました!
3+
date: "2025-06-14"
4+
description: "不具合とひたすら格闘してました(´・ω・`)"
5+
---
6+
7+
# Section of music
8+
9+
どうも! The Infinity'sです!
10+
11+
私、趣味で曲を作ったりしてるんですけど、
12+
今回、その作った曲を公開するためのページを作りました!
13+
14+
![POWER](./player.png "player")
15+
16+
## 主な機能について
17+
18+
このミュージックプレイヤーには以下のような機能があります:
19+
20+
1. 基本的な再生コントロール
21+
- 再生/停止
22+
- 曲の頭出し
23+
- 早送り/巻き戻し
24+
- 次の曲/前の曲への移動
25+
26+
2. 再生速度の調整
27+
- 0.5倍速から2倍速まで切り替え可能
28+
29+
3. イコライザー機能
30+
- 5バンドのイコライザー
31+
- 複数のプリセット
32+
- カスタム設定可能
33+
34+
4. ビジュアライザー
35+
- 線形表示とサークル表示の切り替え
36+
- 音声波形のリアルタイム表示
37+
38+
## 技術的な解説
39+
40+
### オーディオ処理の実装
41+
42+
```tsx
43+
const audioCtxRef = useRef<AudioContext | null>(null);
44+
const elementSource = audioCtxRef.current.createMediaElementSource(
45+
audioRef.current
46+
);
47+
```
48+
49+
Web Audio APIを使用して、オーディオコンテキストを作成しています。これにより、音声信号の加工や分析が可能になります。
50+
51+
### イコライザーの実装
52+
53+
```tsx
54+
const eqFilters: BiquadFilterNode[] = [
55+
audioCtxRef.current.createBiquadFilter(),
56+
// ...
57+
];
58+
59+
const frequencies = [60, 250, 1000, 4000, 16000];
60+
```
61+
62+
5つの周波数帯域(低音~高音)それぞれにBiquadFilterNodeを使用し、音声信号を加工しています。
63+
各フィルターは異なる中心周波数を持ち、gainパラメータで増減を調整できます。
64+
65+
### ビジュアライザーの描画
66+
67+
```tsx
68+
const renderFrame = () => {
69+
analyserNode.getByteFrequencyData(dataArray);
70+
// ...
71+
animationFrameRef.current = requestAnimationFrame(renderFrame);
72+
};
73+
```
74+
75+
AnalyserNodeを使用して音声データをリアルタイムで解析し、Canvas APIで波形を描画しています。
76+
requestAnimationFrameを使用することで、スムーズなアニメーションを実現しています。
77+
78+
### 再生コントロールの実装
79+
80+
```tsx
81+
const handleTogglePlay = () => {
82+
if (!audioRef.current || !audioCtxRef.current) return;
83+
84+
if (audioCtxRef.current.state === "suspended") {
85+
audioCtxRef.current.resume();
86+
setPlayState("play");
87+
}
88+
// ...
89+
};
90+
```
91+
92+
HTMLAudioElementとAudioContextを組み合わせて、再生制御を実装しています。
93+
ユーザーインタラクションに応じて適切に状態を管理しています。
94+
95+
### プレイリスト機能
96+
97+
```tsx
98+
const handleNextTrack = () => {
99+
if (!musicList || musicList.length === 0) return;
100+
const nextId = getNextTrackId();
101+
window.location.href = `/music/${nextId}`;
102+
};
103+
```
104+
105+
現在の曲のインデックスを基に、次の曲や前の曲を特定し、
106+
適切なURLに遷移する実装になっています。
107+
108+
## まとめ
109+
110+
Web Audio APIとCanvas APIを組み合わせることで、
111+
ブラウザ上で本格的な音楽プレイヤーを実現することができました。
112+
特にイコライザーとビジュアライザーの実装には工夫が必要でしたが、
113+
結果として使いやすいUIと高機能な音楽再生機能を備えたプレイヤーが完成しました!
114+
115+
改善点はまだまだありますが、まずは基本機能を実装できて良かったです。
116+
次回は、再生リストの保存機能やシャッフル再生など、
117+
より使いやすい機能を追加していきたいと思います!
222 KB
Loading
341 KB
Loading

src/app/template.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default function Template({ children }: { children: React.ReactNode }) {
1818
minHeight: "100vh",
1919
}}
2020
transition={{
21-
type: "linear",
21+
type: "keyframes",
2222
duration: 2,
2323
}}
2424
>

0 commit comments

Comments
 (0)