Socket
Book a DemoInstallSign in
Socket

tohsaka888-music-player

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tohsaka888-music-player

react music player

0.2.1
latest
Source
npmnpm
Version published
Weekly downloads
14
Maintainers
1
Weekly downloads
 
Created
Source

tohsaka888-music-player

introduction

a music-player based on <audio>,support React.

install

with npm

npm install tohsaka888-music-player

with yarn

yarn add tohsaka888-music-player

Props

propertytyperequireddiscription
musicIdnumberYmusic's unique identification
musicNamestringthe name of music
srcstringmusic url
artistsstring[]artists
nextPlayEventfunctioncallback that click the next button
prevPlayEventfunctioncallback that click the previous button
pauseEventfunctioncallback that click the pause button
playEventfunctioncallback that click the play button
autoPlayfunctionas well as the property of audio
picUrlstringthe cover url of music
likeEventfunctioncallback if user like this music
unLikeEventfunctioncallback if user unlike this muisc
addPlaylistEventfunctioncallback that user add the music into playlist
defaultFavourStatebooleanthe initial state of like button

Useage

import React, { useEffect, useState } from "react";
import "./App.css";
import MusicPlayer from "tohsaka888-music-player";

interface Info {
  songs?: Song[];
  privileges?: Privilege[];
  code: number;
  data?: null;
  msg?: string;
}
interface Privilege {
  id: number;
  fee: number;
  payed: number;
  st: number;
  pl: number;
  dl: number;
  sp: number;
  cp: number;
  subp: number;
  cs: boolean;
  maxbr: number;
  fl: number;
  toast: boolean;
  flag: number;
  preSell: boolean;
  playMaxbr: number;
  downloadMaxbr: number;
  rscl: null;
  freeTrialPrivilege: FreeTrialPrivilege;
  chargeInfoList: ChargeInfoList[];
}
interface ChargeInfoList {
  rate: number;
  chargeUrl: null;
  chargeMessage: null;
  chargeType: number;
}
interface FreeTrialPrivilege {
  resConsumable: boolean;
  userConsumable: boolean;
}
interface Song {
  name: string;
  id: number;
  pst: number;
  t: number;
  ar: Ar[];
  alia: string[];
  pop: number;
  st: number;
  rt: string;
  fee: number;
  v: number;
  crbt: null;
  cf: string;
  al: Al;
  dt: number;
  h: H;
  m: H;
  l: H;
  a: null;
  cd: string;
  no: number;
  rtUrl: null;
  ftype: number;
  rtUrls: any[];
  djId: number;
  copyright: number;
  s_id: number;
  mark: number;
  originCoverType: number;
  originSongSimpleData: null;
  tagPicList: null;
  resourceState: boolean;
  version: number;
  songJumpInfo: null;
  entertainmentTags: null;
  single: number;
  noCopyrightRcmd: null;
  rtype: number;
  rurl: null;
  mv: number;
  mst: number;
  cp: number;
  publishTime: number;
  tns: string[];
}
interface H {
  br: number;
  fid: number;
  size: number;
  vd: number;
}
interface Al {
  id: number;
  name: string;
  picUrl: string;
  tns: any[];
  pic_str: string;
  pic: number;
}
interface Ar {
  id: number;
  name: string;
  tns: any[];
  alias: any[];
}

interface Music {
  data: Datum[];
  code: number;
}
interface Datum {
  id: number;
  url: string;
  br: number;
  size: number;
  md5: string;
  code: number;
  expi: number;
  type: string;
  gain: number;
  fee: number;
  uf: null;
  payed: number;
  flag: number;
  canExtend: boolean;
  freeTrialInfo: null;
  level: null;
  encodeType: null;
  freeTrialPrivilege: FreeTrialPrivilege;
  freeTimeTrialPrivilege: FreeTimeTrialPrivilege;
  urlSource: number;
}
interface FreeTimeTrialPrivilege {
  resConsumable: boolean;
  userConsumable: boolean;
  type: number;
  remainTime: number;
}

function App() {
  const [url, setUrl] = useState<string>("");
  const [info, setInfo] = useState<{
    name: string;
    artist: string[];
    picUrl: string;
  }>({
    name: "",
    artist: [],
    picUrl: "",
  });
  useEffect(() => {
    const getMusicUrl = async () => {
      const res = await fetch(
        `https://netease-cloud-music-api-tohsaka888.vercel.app/song/url?id=1824020871&realIP=116.25.146.177`
      );
      const data: Music = await res.json();
      setUrl(data.data[0].url);
    };

    const getMusicInfo = async () => {
      const res = await fetch(
        `https://netease-cloud-music-api-tohsaka888.vercel.app/song/detail?ids=1824020871&realIP=116.25.146.177`
      );
      const data: Info = await res.json();
      const songs = data.songs || [];
      const artist = songs[0].ar.map((item) => item.name);
      const name = songs[0].name;
      const picUrl = songs[0].al.picUrl;
      setInfo({ name: name, artist, picUrl });
    };
    getMusicUrl();
    getMusicInfo();
  }, []);
  return (
    <div className="App">
      <MusicPlayer
        musicId={0}
        musicName={info.name}
        autoPlay
        artists={info.artist}
        src={url}
        picUrl={info.picUrl}
      />
    </div>
  );
}

export default App;

Demo

click me to view the demo

Keywords

music-player

FAQs

Package last updated on 27 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.