Giter Site home page Giter Site logo

blockly-field-player's Introduction

blockly-field-player Built on Blockly

A Blockly audio player field.

About

Audio player capabilities right from the Google Blockly Field.

  • Interactive audio visualization using Web Audio and Canvas based on wavesurfer.js
  • Public API: load(), unload(), play(), pause(), stop()
  • Player state change events
  • Audio source cache
  • Audio source autoload
  • XHR fetch with credentials
  • Color scheme configuration

blockly-field-player

Installation

npm

npm install --save blockly-field-player

yarn

yarn add blockly-field-player

Build

npm run build

or

yarn build

Usage

JavaScript

import * as Blockly from 'blockly'
import {FieldPlayer} from 'blockly-field-player'

Blockly.Blocks['test_field'] = {
  init: function () {
    this.appendDummyInput()
      .appendField(new FieldPlayer('http://localhost/test.mp3'), 'FIELDNAME')
  }
};

JSON

import * as Blockly from 'blockly'
import 'blockly-field-text-box'

Blockly.defineBlocksWithJsonArray([
    {
        "type": "test_field",
        "message0": "%1",
        "args0": [
            {
                "type": "field_player",
                "name": "FIELDNAME",
                "src": "http://localhost/test.mp3"
            }
        ]
    }])

Run in browser

<script src="./dist/index.js"></script>

note: you need to build the package first.

Configuration

You can provide options object:

Blockly.defineBlocksWithJsonArray([
    {
        "type": "test_field",
        "message0": "%1",
        "args0": [
            {
                "type": "field_player",
                "name": "FIELDNAME",
                "src": "http://localhost/test.mp3",
                "options": {
                    primaryColor: '#DEA922',
                    secondaryColor: '#E2D0A7',
                    backgroundColor: '#FCF3D8'
                }
            }
        ]
    }])

Options list

  • primaryColor
  • secondaryColor
  • backgroundColor
  • autoLoad (see notes about Autoload option)

Events

You can listen for various of player state events, such as:

  • notloaded
  • readytoload
  • unloaded
  • loading
  • loaded
  • playing
  • paused
  • error

Just subscribe to state events from the player instance:

Blockly.Blocks['test_field'] = {
  init: function () {
      const player = new FieldPlayer('http://localhost/test.mp3')
      player.on('state', state => console.debug(state))
      this.appendDummyInput().appendField(player, 'FIELDNAME')
  }
};

Autoload

By default, even if media source is provided, player will not load it automatically. If you want to change this behaviour and load media to cache during field render, set autoLoad option to true.

const player = new FieldPlayer('http://localhost/test.mp3', { autoLoad: true })

License

Apache 2.0

blockly-field-player's People

Contributors

tomas-berg avatar

Watchers

 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.