Add functionality for playing audio files.

This commit is contained in:
Sean Lip
2016-08-09 17:29:53 -07:00
parent 5aa3add06c
commit 93af9c59b3
13 changed files with 84 additions and 10 deletions

View File

@@ -25,15 +25,16 @@ the main component to be loaded. This will usually be blocklyApp.AppView, but
if you have another component that wraps it, use that one instead. if you have another component that wraps it, use that one instead.
Customizing the Toolbar Customizing the Toolbar and Audio
----------------------- ---------------------------------
The Accessible Blockly workspace comes with a customizable toolbar. The Accessible Blockly workspace comes with a customizable toolbar.
To customize the toolbar, you will need to declare an ACCESSIBLE_GLOBALS object To customize the toolbar, you will need to declare an ACCESSIBLE_GLOBALS object
in the global scope that looks like this: in the global scope that looks like this:
var ACCESSIBLE_GLOBALS = { var ACCESSIBLE_GLOBALS = {
toolbarButtonConfig: [] toolbarButtonConfig: [],
mediaPathPrefix: null
}; };
The value corresponding to 'toolbarButtonConfig' can be modified by adding The value corresponding to 'toolbarButtonConfig' can be modified by adding
@@ -43,6 +44,9 @@ two keys:
- 'text' (the text to display on the button) - 'text' (the text to display on the button)
- 'action' (the function that gets run when the button is clicked) - 'action' (the function that gets run when the button is clicked)
In addition, if you want audio to be played, set mediaPathPrefix to the
location of the accessible/media folder.
Limitations Limitations
----------- -----------

View File

@@ -64,7 +64,8 @@ blocklyApp.AppView = ng.core
// https://www.sitepoint.com/angular-2-components-providers-classes-factories-values/ // https://www.sitepoint.com/angular-2-components-providers-classes-factories-values/
providers: [ providers: [
blocklyApp.ClipboardService, blocklyApp.NotificationsService, blocklyApp.ClipboardService, blocklyApp.NotificationsService,
blocklyApp.TreeService, blocklyApp.UtilsService] blocklyApp.TreeService, blocklyApp.UtilsService,
blocklyApp.AudioService]
}) })
.Class({ .Class({
constructor: [blocklyApp.NotificationsService, function(_notificationsService) { constructor: [blocklyApp.NotificationsService, function(_notificationsService) {

View File

@@ -0,0 +1,57 @@
/**
* AccessibleBlockly
*
* Copyright 2016 Google Inc.
* https://developers.google.com/blockly/
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Angular2 Service that plays audio files.
* @author sll@google.com (Sean Lip)
*/
blocklyApp.AudioService = ng.core
.Class({
constructor: [function() {
// We do not play any audio unless a media path prefix is specified.
this.canPlayAudio = false;
if (ACCESSIBLE_GLOBALS.hasOwnProperty('mediaPathPrefix')) {
this.canPlayAudio = true;
var mediaPathPrefix = ACCESSIBLE_GLOBALS['mediaPathPrefix'];
this.AUDIO_PATHS_ = {
'connect': mediaPathPrefix + 'click.mp3',
'delete': mediaPathPrefix + 'delete.mp3'
};
}
// TODO(sll): Add ogg and mp3 fallbacks.
this.cachedAudioFiles_ = {};
}],
play_: function(audioId) {
if (this.canPlayAudio) {
if (!this.cachedAudioFiles_.hasOwnProperty(audioId)) {
this.cachedAudioFiles_[audioId] = new Audio(
this.AUDIO_PATHS_[audioId]);
}
this.cachedAudioFiles_[audioId].play();
}
},
playConnectSound: function() {
this.play_('connect');
},
playDeleteSound: function() {
this.play_('delete');
}
});

View File

@@ -26,7 +26,8 @@ blocklyApp.ClipboardService = ng.core
.Class({ .Class({
constructor: [ constructor: [
blocklyApp.NotificationsService, blocklyApp.UtilsService, blocklyApp.NotificationsService, blocklyApp.UtilsService,
function(_notificationsService, _utilsService) { blocklyApp.AudioService,
function(_notificationsService, _utilsService, _audioService) {
this.clipboardBlockXml_ = null; this.clipboardBlockXml_ = null;
this.clipboardBlockPreviousConnection_ = null; this.clipboardBlockPreviousConnection_ = null;
this.clipboardBlockNextConnection_ = null; this.clipboardBlockNextConnection_ = null;
@@ -34,6 +35,7 @@ blocklyApp.ClipboardService = ng.core
this.markedConnection_ = null; this.markedConnection_ = null;
this.notificationsService = _notificationsService; this.notificationsService = _notificationsService;
this.utilsService = _utilsService; this.utilsService = _utilsService;
this.audioService = _audioService;
}], }],
areConnectionsCompatible_: function(blockConnection, connection) { areConnectionsCompatible_: function(blockConnection, connection) {
// Check that both connections exist, that it's the right kind of // Check that both connections exist, that it's the right kind of
@@ -130,6 +132,7 @@ blocklyApp.ClipboardService = ng.core
default: default:
connection.connect(reconstitutedBlock.outputConnection); connection.connect(reconstitutedBlock.outputConnection);
} }
this.audioService.playConnectSound();
this.notificationsService.setStatusMessage( this.notificationsService.setStatusMessage(
this.utilsService.getBlockDescription(reconstitutedBlock) + ' ' + this.utilsService.getBlockDescription(reconstitutedBlock) + ' ' +
Blockly.Msg.PASTED_BLOCK_FROM_CLIPBOARD_MSG); Blockly.Msg.PASTED_BLOCK_FROM_CLIPBOARD_MSG);
@@ -151,6 +154,7 @@ blocklyApp.ClipboardService = ng.core
if (this.areConnectionsCompatible_( if (this.areConnectionsCompatible_(
this.markedConnection_, potentialConnections[i])) { this.markedConnection_, potentialConnections[i])) {
this.markedConnection_.connect(potentialConnections[i]); this.markedConnection_.connect(potentialConnections[i]);
this.audioService.playConnectSound();
connectionSuccessful = true; connectionSuccessful = true;
break; break;
} }

BIN
accessible/media/click.mp3 Normal file

Binary file not shown.

BIN
accessible/media/click.ogg Normal file

Binary file not shown.

BIN
accessible/media/click.wav Normal file

Binary file not shown.

BIN
accessible/media/delete.mp3 Normal file

Binary file not shown.

BIN
accessible/media/delete.ogg Normal file

Binary file not shown.

BIN
accessible/media/delete.wav Normal file

Binary file not shown.

View File

@@ -102,13 +102,15 @@ blocklyApp.WorkspaceTreeComponent = ng.core
constructor: [ constructor: [
blocklyApp.ClipboardService, blocklyApp.NotificationsService, blocklyApp.ClipboardService, blocklyApp.NotificationsService,
blocklyApp.TreeService, blocklyApp.UtilsService, blocklyApp.TreeService, blocklyApp.UtilsService,
blocklyApp.AudioService,
function( function(
_clipboardService, _notificationsService, _treeService, _clipboardService, _notificationsService, _treeService,
_utilsService) { _utilsService, _audioService) {
this.clipboardService = _clipboardService; this.clipboardService = _clipboardService;
this.notificationsService = _notificationsService; this.notificationsService = _notificationsService;
this.treeService = _treeService; this.treeService = _treeService;
this.utilsService = _utilsService; this.utilsService = _utilsService;
this.audioService = _audioService;
}], }],
getBlockDescription: function() { getBlockDescription: function() {
return this.utilsService.getBlockDescription(this.block); return this.utilsService.getBlockDescription(this.block);
@@ -172,6 +174,7 @@ blocklyApp.WorkspaceTreeComponent = ng.core
var that = this; var that = this;
this.removeBlockAndSetFocus_(this.block, function() { this.removeBlockAndSetFocus_(this.block, function() {
that.block.dispose(true); that.block.dispose(true);
that.audioService.playDeleteSound();
}); });
setTimeout(function() { setTimeout(function() {

View File

@@ -19,6 +19,7 @@
<script src="../../accessible/libs/angular2-all.umd.min.js"></script> <script src="../../accessible/libs/angular2-all.umd.min.js"></script>
<script src="../../accessible/utils.service.js"></script> <script src="../../accessible/utils.service.js"></script>
<script src="../../accessible/audio.service.js"></script>
<script src="../../accessible/notifications.service.js"></script> <script src="../../accessible/notifications.service.js"></script>
<script src="../../accessible/clipboard.service.js"></script> <script src="../../accessible/clipboard.service.js"></script>
<script src="../../accessible/tree.service.js"></script> <script src="../../accessible/tree.service.js"></script>
@@ -31,7 +32,7 @@
<script src="../../accessible/workspace.component.js"></script> <script src="../../accessible/workspace.component.js"></script>
<script src="../../accessible/app.component.js"></script> <script src="../../accessible/app.component.js"></script>
<link rel="stylesheet" href="../../media/accessible.css"> <link rel="stylesheet" href="../../accessible/media/accessible.css">
<style> <style>
body { body {
background-color: #fff; background-color: #fff;
@@ -48,8 +49,10 @@
</style> </style>
</head> </head>
<body> <body>
<h1><a href="https://developers.google.com/blockly/">Blockly</a> &gt; <h1>
<a href="../index.html">Demos</a> &gt; Accessible Blockly</h1> <a href="https://developers.google.com/blockly/">Blockly</a> &gt;
<a href="../index.html">Demos</a> &gt; Accessible Blockly
</h1>
<p>This is a simple demo of a version of Blockly designed for screen readers.</p> <p>This is a simple demo of a version of Blockly designed for screen readers.</p>
@@ -70,7 +73,9 @@
var ACCESSIBLE_GLOBALS = { var ACCESSIBLE_GLOBALS = {
// Additional buttons for the workspace toolbar that // Additional buttons for the workspace toolbar that
// go before the "Clear Workspace" button. // go before the "Clear Workspace" button.
toolbarButtonConfig: [] toolbarButtonConfig: [],
// Prefix of path to sound files.
mediaPathPrefix: '../../accessible/media/'
}; };
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
ng.platform.browser.bootstrap(blocklyApp.AppView); ng.platform.browser.bootstrap(blocklyApp.AppView);