0.0.5 • Published 6 years ago

qm-player v0.0.5

Weekly downloads
1
License
ISC
Repository
-
Last release
6 years ago

QMplayer

Install

$ npm i qm-player

Use

const QMplayer =  require('qm-player')
const player = new QMplayer()

Api

attribute

loop

A Boolean attribute: if specified, will automatically seek back to the start upon reaching the end of the audio.

muted

A Boolean attribute which indicates whether the audio will be initially silenced. Its default value is false.

currentTime

set or get currentTime

volume

set or get volume

duration

get audio duration

muted

set or get audio muted

index

get now song in playlist index

playlist

return song playlist

version

return QMplayer varsion

Methods

searchMusic(options,callback) 搜索歌曲

  1. options Object
  2. callback Function

test

player.searchMusic({
  text:'新不了情', // Song name
  page:1,	  // Page number
  limit:20, 	  // Limit number
},function(result){
  	console.log(result)
})

result demo

{
    "code": 0,
    "data": {
        "keyword": "新不了情",
        "priority": 0,
        "qc": [],
        "semantic": {
            "curnum": 0,
            "curpage": 1,
            "list": [],
            "totalnum": 0
        },
        "song": {
            "curnum": 1,
            "curpage": 1,
            "list": [
                {
                    "albumid": 227338,
                    "albummid": "002pp9Ti38XyZ3",
                    "albumname": "新不了情",
                    "albumname_hilight": "<em>新不了情</em>",
                    "alertid": 11,
                    "belongCD": 0,
                    "cdIdx": 1,
                    "chinesesinger": 0,
                    "docid": "6652281398537732715",
                    "format": "qqhq;common;mp3common;wmacommon;crcommon",
                    "grp": [],
                    "interval": 305,
                    "isonly": 0,
                    "lyric": "《新不了情》电视剧主题曲",
                    "lyric_hilight": "《<em>新不了情</em>》电视剧主题曲",
                    "media_mid": "000tUvCY4H1UqK",
                    "msgid": 0,
                    "newStatus": 2,
                    "nt": 3648724330,
                    "pay": {
                        "payalbum": 0,
                        "payalbumprice": 0,
                        "paydownload": 0,
                        "payinfo": 0,
                        "payplay": 0,
                        "paytrackmouth": 0,
                        "paytrackprice": 0
                    },
                    "preview": {
                        "trybegin": 0,
                        "tryend": 0,
                        "trysize": 0
                    },
                    "pubtime": 1179158400,
                    "pure": 0,
                    "singer": [
                        {
                            "id": 4607,
                            "mid": "000aw4WC2EQYTv",
                            "name": "张靓颖",
                            "name_hilight": "张靓颖"
                        }
                    ],
                    "size128": 4896853,
                    "size320": 12227912,
                    "sizeape": 0,
                    "sizeflac": 0,
                    "sizeogg": 4954683,
                    "songid": 435789,
                    "songmid": "000tUvCY4H1UqK",
                    "songname": "新不了情",
                    "songname_hilight": "<em>新不了情</em>",
                    "songurl": "http://y.qq.com/#type=song&id=435789",
                    "strMediaMid": "000tUvCY4H1UqK",
                    "stream": 1,
                    "switch": 81719,
                    "t": 0,
                    "tag": 12,
                    "type": 0,
                    "ver": 0,
                    "vid": "u0013gojpai"
                }
            ],
            "totalnum": 241
        },
        "tab": 0,
        "taglist": [],
        "totaltime": 0,
        "zhida": {
            "chinesesinger": 0,
            "type": 0
        }
    },
    "message": "",
    "notice": "",
    "subcode": 0,
    "time": 1526581002,
    "tips": ""
}

playListAdd(musicId) 添加歌曲到播放列表

  1. musicId String

musicId in the method searchMusic callback result data songid or songmid

{
  "songid": 435789,
  "songmid": "000tUvCY4H1UqK",
  "songname": "新不了情",
  "songname_hilight": "<em>新不了情</em>",
}

test

player.playListAdd('000tUvCY4H1UqK') //use songmid

//or
player.playListAdd('435789') //use songid

// Check the playlist
console.log(player.playlist)

play(musicId?) 播放歌曲

  1. musicId String Optional

musicId in the method searchMusic callback result data songid or songmid

test

player.play('000tUvCY4H1UqK') //use songmid

// or

player.play('435789')//use songid

//or 

player.play() // Select auto play in the playlist

playNext() 下一曲

test

player.playNext()

playPrev() 上一曲

test

player.playPrev()

pause() 暂停

test

player.pause()

toggle() 切换播放状态

test

player.toggle()

on(eventType,eventHandler) 添加事件绑定

  1. eventType String

    Supported event types error|play|pause

  2. eventHandler Function eventHandler

test

player.on('add',handler)
player.on('error',e=>console.log(e))
player.on('play',e=>console.log(e))
player.on('pause',e=>console.log(e))

off(eventType,eventHandler) 取消事件绑定

  1. eventType String

    Supported event types error|play|pause

  2. eventHandler Function eventHandler

test

let handler = e => { console.log(e) }

player.off('add',handler)
player.off('error',handler)
player.off('play',handler)
player.off('pause',handler)
0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago