Plugins & Extensions

Mở rộng chức năng của ZiPlayer với hệ thống plugin mạnh mẽ. Hỗ trợ YouTube, SoundCloud, Spotify và tạo plugins tùy chỉnh.

YouTube Plugin

Hỗ trợ tìm kiếm và phát nhạc từ YouTube

  • Video search
  • Playlist support
  • Live streams
  • High quality audio

SoundCloud Plugin

Tích hợp với SoundCloud cho âm nhạc độc lập

  • Track search
  • User playlists
  • Comments support
  • Waveform data

Spotify Plugin

Kết nối với Spotify cho trải nghiệm âm nhạc phong phú

  • Spotify search
  • Playlist import
  • Artist albums
  • Recommendations

Custom Plugins

Tạo plugins tùy chỉnh cho nguồn âm nhạc riêng

  • Custom APIs
  • Local files
  • Radio streams
  • Database integration

Built-in Plugins

ZiPlayer đi kèm với các plugins phổ biến nhất, sẵn sàng sử dụng ngay.

1import { 
2  YouTubePlugin, 
3  SoundCloudPlugin, 
4  SpotifyPlugin,
5  TTSPlugin 
6} from "@ziplayer/plugin";
7
8const manager = new PlayerManager({
9  plugins: [
10   	new TTSPlugin({ defaultLang: "vi" }),
11    new YouTubePlugin(),
12		new SoundCloudPlugin(),
13		new SpotifyPlugin()
14  ]
15});

YouTube

  • Hỗ trợ video và audio
  • Playlist và live streams
  • Chất lượng cao

SoundCloud

  • Âm nhạc độc lập
  • Playlist người dùng
  • Metadata phong phú

Spotify

  • Thư viện lớn
  • Playlist và albums
  • Gợi ý thông minh

Tạo Custom Plugin

Tạo plugin tùy chỉnh để tích hợp với nguồn âm nhạc riêng của bạn.

Plugin Structure

1// Các methods có sẵn trong BasePlugin
2class MyPlugin extends BasePlugin {
3  name = "my-plugin";
4  
5  // Bắt buộc: Tìm kiếm bài hát
6  async search(query: string): Promise<Track[]> {
7    // Trả về danh sách bài hát
8  }
9  
10  // Bắt buộc: Lấy stream URL
11  async getStream(url: string): Promise<string> {
12    // Trả về URL stream
13  }
14  
15  // Tùy chọn: Xử lý playlist
16  async getPlaylist(url: string): Promise<Track[]> {
17    // Trả về danh sách bài hát từ playlist
18  }
19  
20  // Tùy chọn: Lấy thông tin chi tiết
21  async getInfo(url: string): Promise<TrackInfo> {
22    // Trả về thông tin chi tiết bài hát
23  }
24}

Example Implementation

1import { BasePlugin } from "@ziplayer/plugin";
2
3export class CustomPlugin extends BasePlugin {
4  name = "custom-plugin";
5  
6  async search(query: string) {
7    // Tìm kiếm bài hát từ nguồn tùy chỉnh
8    const results = await this.fetchFromAPI(query);
9    return results.map(item => ({
10      title: item.name,
11      url: item.streamUrl,
12      duration: item.duration,
13      thumbnail: item.cover
14    }));
15  }
16  
17  async getStream(url: string) {
18    // Lấy stream URL để phát
19    return await this.resolveStream(url);
20  }
21  
22  private async fetchFromAPI(query: string) {
23    // Logic tìm kiếm tùy chỉnh
24    const response = await fetch(`https://api.example.com/search?q=${query}`);
25    return response.json();
26  }
27}

Using Your Plugin

1import { PlayerManager } from "ziplayer";
2import { CustomPlugin } from "./CustomPlugin";
3
4const manager = new PlayerManager({
5  plugins: [
6    new CustomPlugin(),
7    // Các plugins khác...
8  ]
9});
10
11// Plugin sẽ tự động được sử dụng khi tìm kiếm
12const player = manager.create(guildId);
13await player.play("tên bài hát", userId);

Tiếp theo: Extensions

Tìm hiểu cách sử dụng extensions để mở rộng chức năng player.

Xem Extensions