1 Star 0 Fork 0

lovelacelee / Player

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Embeddable Goodness, by ToneDen

The ToneDen SDK is loaded asynchronously, which means your page doesn't have to wait for the SDK to load before rendering. This means that loading it is a little more complicated than just including a <script> tag. Don't worry though, we've taken care of all the complicated stuff for you. Just copy the snippet below into your HTML page, enter your SoundCloud consumer key, and replace the commented portion with your code calling the SDK. If you don't have a SoundCloud consumer key, you can create one here.

<script>
    (function() {
        var script = document.createElement("script");

        script.type = "text/javascript";
        script.async = true;
        script.src = "//sd.toneden.io/production/v2/toneden.loader.js"

        var entry = document.getElementsByTagName("script")[0];
        entry.parentNode.insertBefore(script, entry);
    }());

    ToneDenReady = window.ToneDenReady || [];
    ToneDenReady.push(function() {
        ToneDen.configure({
            soundcloudConsumerKey: '<YOUR SOUNDCLOUD CONSUMER KEY HERE>'
        });
        // call SDK functions (ToneDen.player.create(), etc.)
    });
</script>

Player

A pure JS customizable audio player for your SoundCloud.

JS API, responsive, customizable. Demo at https://www.toneden.io/player.

alt tag

Sample Embed Code:

<script>
    (function() {
        var script = document.createElement("script");

        script.type = "text/javascript";
        script.async = true;
        script.src = "//sd.toneden.io/production/v2/toneden.loader.js"

        var entry = document.getElementsByTagName("script")[0];
        entry.parentNode.insertBefore(script, entry);
    }());

    ToneDenReady = window.ToneDenReady || [];
    ToneDenReady.push(function() {
        ToneDen.configure({
            soundcloudConsumerKey: '<YOUR SOUNDCLOUD CONSUMER KEY HERE>'
        });
        // This is where all the action happens:
        ToneDen.player.create({
            dom: "#player",
            eq: "waves",
            skin: "light",
            tracksPerArtist: 4,
            urls: [
                "https://soundcloud.com/mutantbreakz/blacklist-vs-alt-a-fire"
            ]
        });
    });
</script>

Global Player and Play Queues

Documentation coming soon!

API

ToneDen

  • .configure
    • configure(params) Sets global SDK options. Parameters:
      • debug
        default: false
        True to output debug messages to the console.
      • soundcloudConsumerKey
        You now have to provide your own SoundCloud consumer key in order to stream tracks.
        Because of SoundCloud's new daily stream limits, we can't afford to use a single consumer key for everyone using the player.
        Sorry for the inconvenience!
  • .player
    • .create(params)
      Creates and returns a new player instance according to the given parameters object. Parameters:
      • feed
        default: false
        True to display a simplified version of the player, no bells and whistles here.
      • keyboardEvents
        default: false
        True to listen to keyboard events on the document body to control the player.
        Left arrow key returns to the previous track, right arrow key skips to the next, and spacebar plays/pauses the current track.
      • mini
        default: false
        True to use the 'mini' version of the player. This renders as a narrower bar with controls laid out horizontally. For an example, check out the player on ToneDen OneSheets.
      • shrink
        default: true
        By default, the player shrinks to the size of its parent container. Set this to false to disable that behavior.
      • single
        default: false
        True to force the player to render as if there were only one track in the playlist.
        This parameter is internally set to true if the playlist has only one track, unless the single parameter is explicitly set to false.
      • skin
        default: 'light'
        The player color scheme to render. Options are 'light', 'dark', 'mojave', and 'aurora'.
      • tracksPerArtist
        default: 10
        How many tracks to load from an artist's SoundCloud account when the artist's SoundCloud URL is specified in the urls parameter.
      • useCustomPurchaseTitle
        default: true
        Whether to use tracks' custom purchase titles. If false, the purchase link text will be 'BUY'.
    • .getInstanceByDom(dom)
      Returns the player instance that is associated with the given dom selector string.
    • .setRepeat(repeat)
      Sets whether players should repeat their songs.
    • .setVolume(level)
      Sets the volume level on all players. Level should be an integer between 0 and 100, inclusive.
    • .global
      These functions act on the page's global player instance, if one exists.
      • .nowPlaying()
        Returns the track that the global player is currently playing.
      • .playTrack(url)
        Loads and starts playing a track in the global player.
      • .queueTrack(track, index)
        Adds a track to the global player's queue.
      • **.setDefaultTracks(tracks, insertLocation)
        Sets the default list of tracks to be played if the global player's queue runs out of tracks.
      • .togglePause(paused)
        Sets the play state of the global player.
      • .unqueueIndex(index)
        Removes a track from the global play queue at the specified index.

Player Instance

  • id
    Randomly generated ID, unique to the player instance.
  • .destroy()
    Destroys the player instance and clears the containing element's HTML.
  • .next(play)
    Skip to the next track, and play it if play is true.
  • .prev()
    Jumps to the previous track.
  • .skipTo(index)
    Jumps to track number index.
  • .togglePause(paused)
    Toggles the paused state of the player, or sets it to the value of the 'paused' argument if provided.
  • .update(params)
    Updates the player with the given parameters. All parameters are supported except 'dom'.

Sample API Usage:

ToneDen.player.getInstanceByDom("#player").togglePause(false); // The player will start playing, if it isn't already.
ToneDen.player.getInstanceByDom("#player").togglePause(true); // The player will pause.
ToneDen.player.getInstanceByDom("#player").next(); // Play the next track in the list.

Development

Setup

  1. Add the following lines to /etc/hosts:
127.0.0.1 publisher.dev
127.0.0.1 widget.dev
  1. Add the following lines to /etc/apache2/extra/https-vhosts.conf:
<VirtualHost *:80>  
    DocumentRoot "<repo location>/toneden-sdk/test"  
    ServerName publisher.dev  
</VirtualHost>  
<VirtualHost *:80>  
    DocumentRoot "<repo location>/toneden-sdk"  
    ServerName widget.dev  
</VirtualHost>  
  1. Restart Apache.
  2. Install NPM and Grunt.
  3. Run npm install in the root directory.
  4. Navigate to publisher.dev in your browser of choice. This will load test/index.html, which includes a script snippet that loads toneden.loader.js from the domain widget.dev to simulate a cross-origin environment.

Building

We use Webpack to compile the player and all of it's dependencies into a single file. When you run grunt from the root directory, the Webpack dev server will start. From this point on, any changes you make to files in the repo will cause Webpack to rebuild /toneden.js and /toneden.loader.js.

Don't use files built by the webpack dev server in production- they're huge! Run grunt --production to build a minified version.

grunt --dev will compile a readable, debug-friendly version of the scripts, while grunt --production will make a minified version.

Overview

The loader/ directory contains the scripts that manage (surprise!) loading the SDK when embedded in a webpage. You probably won't have to touch anything in this directory, but here's how it works:

The loader script (toneden.loader.js) uses webpack to asynchronously load the SDK script (toneden.js) from the ToneDen CDN. This system allows embedding pages to include (either asynchronously or synchronously) the relatively small loading script, which then loads the much larger SDK files in a non-blocking way. When the SDK has been loaded, the loader calls all the functions in the global ToneDenReady array, allowing developers to access the functionality of the SDK. (Inspired by/copied from the Shootitlive folks, who are way smarter than me!)

The sdk/ directory contains all the good stuff. The file index.js is the hub of the action. It loads all the functions of the SDK (currently only the player) as dependencies, and returns them so that they can be attached to the global ToneDen object.

Questions?

You can contact us on GitHub or on Twitter: @tonedenmusic

License

MIT License

Copyright (c) 2014 ToneDen, Inc Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
JavaScript 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/lovelacelee/Player.git
git@gitee.com:lovelacelee/Player.git
lovelacelee
Player
Player
master

搜索帮助

14c37bed 8189591 565d56ea 8189591