Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

blockly-field-player

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blockly-field-player

A Blockly audio player field

  • 1.0.0
  • unpublished
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

You need to build the package first.

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

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
  • 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

Keywords

FAQs

Package last updated on 06 Aug 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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc