Code Monkey home page Code Monkey logo

cplayer's Introduction

cPlayer

Maybe It's the best code I wrote.

Warning: This can only be loaded well in the MODERN-BROWSER(eg. Edge14+,Firefox(Current Version,Chrome(Current Version)...))


Install && Build

npm install
npm run dist

Make a DEMO

npm run demo

Usage

HTML

<html>
    <head>
        ...
        <link rel="stylesheet" href=".../cplayer.min.css">
        ...
    </head>
    <body>
        ...
        <div id="here"></div>
        ...
        <script src=".../cplayer.min.js"></script>
    </body>
</html>

Javascript

let cp = new cPlayer({
    "element":document.getElementById("here"),
    "list":[
        {
            "name":"NINELIE", //The Music's Name
            "artist":"Aimer/EGOist",//The Music's Artist
            "image":"http://xxxxx",//The Music's Cover
            "url":"http://xxxxx",//The Music's URL
            "loop":true,//If loop === true,the Music will be played again and again.
            "lyric":`
            [00:00.00]XXXXXXXX
            .....
            [00:99.99][11:99.99]XXXXX
            ` //The Lyric(Extra)
        },
        {
            .......
        },
        .........
    ]
});

APIs

  • cp.play() // Play
  • cp.pause() // Pause
  • cp.volume(number) // Set Volume
  • cp.isMuted() // Return if the music is muted
  • cp.isPaused() // Return if the music is paused
  • cp.last() // Set the previous music
  • cp.next() // Set the next music
  • cp.to(now) // Set the music you set
  • cp.hasLyric(id) // Return if the music you set has lyric
  • cp.showLyric() // Show the Lyric Body,if the music at that time hasn't lyric,DO NOTHING;if the Lyric Body is already shown,HIDE IT.
  • cp.hideLyric() // Hide the Lyric Body
  • cp.hasList()
  • cp.showList()
  • cp.hideList() // (The Same As Above)
  • refreshList() // Refresh the List from __LIST__(unuseful)
  • cp.add(options) // Add music(the options is like above)
  • cp.lyric(a) // Set Lyric or Get Lyric
  • cp.refreshLyric() // Refresh the lyric now from __LYRIC__(unuseful)
  • cp.updateTime() // Set Music's Current Time
  • cp.slideLyric(time) //Core Lyric Process
  • cp.on(eventName,func) //NEW! Set Events

Events

Now Here are some events.

Event param Note
play
pause
volumechange Return the music's own event object
timeupdate The same as above
canplaythrough
ended
toggle
previous
next
changeList
changeLyric
slideList If showed,the param is true;If not,the param is false
slideLyric The same as above
clickListPower
clickLyricPower
clickVolumePower

Usage

cp.on("slideLyric",([showed])=>{
    if(showed===true){
        //...
    }else{
        //...
    }
}).on("timeupdate",([ev])=>{
    //...
})

TODOLIST

  • Playlist Order Mode(Random/Asc/Desc(Order By ID))

DEMO

Click Here to See the Demo

cplayer's People

Contributors

copay avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.