Skip to content

Commit

Permalink
Fixes build process, ES5 examples, supports iOS9 (#20)
Browse files Browse the repository at this point in the history
* Fixes build process, es5 examples, support iOS9

* Add external node typings
  • Loading branch information
bigtimebuddy authored Jun 20, 2017
1 parent aa415e1 commit e367847
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 4,229 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ WebAudio API playback without any Flash shims or HTML Audio fallback. Modern aud
* Chrome 58+
* Firefox 49+
* Safari 10+
* iOS 10+
* iOS 9+

## Usage

Expand Down
62 changes: 30 additions & 32 deletions examples/client/app.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,61 @@
const $ = document.querySelector.bind(document);
const $$ = document.querySelectorAll.bind(document);
var $ = document.querySelector.bind(document);
var $$ = document.querySelectorAll.bind(document);

const manifest = {
var manifest = {
applause: 'resources/applause.mp3',
bird: 'resources/bird.mp3',
boing: 'resources/boing.mp3',
mechanical: 'resources/mechanical.mp3',
whistle: 'resources/whistle.mp3'
};

for (let name in manifest) {
for (var name in manifest) {
PIXI.loader.add(name, manifest[name]);
}

const distort = new PIXI.sound.filters.DistortionFilter();
const stereo = new PIXI.sound.filters.StereoFilter();
const equalizer = new PIXI.sound.filters.EqualizerFilter();
var distort = new PIXI.sound.filters.DistortionFilter();
var stereo = new PIXI.sound.filters.StereoFilter();
var equalizer = new PIXI.sound.filters.EqualizerFilter();

PIXI.loader.load(function(loader, resources) {
const singleInstance = $("#singleInstance");
const loop = $("#loop");
const speed = $("#speed");
const volume = $('#volume');
const stops = $$(`button[data-stop]`);
for (let i = 0; i < stops.length; i++) {
const button = stops[i];
const progressBar = $(`#progress-${button.dataset.stop}`);
button.addEventListener('click', function() {
const sound = resources[this.dataset.stop].sound;
var singleInstance = $("#singleInstance");
var loop = $("#loop");
var speed = $("#speed");
var volume = $('#volume');
var stops = $$(`button[data-stop]`);
for (var i = 0; i < stops.length; i++) {
stops[i].addEventListener('click', function() {
var progressBar = $(`#progress-${this.dataset.stop}`);
var sound = resources[this.dataset.stop].sound;
sound.stop();
progressBar.style.width = '';
});
}

const plays = $$(`button[data-play]`);
for (let i = 0; i < plays.length; i++) {
const button = plays[i];
const progressBar = $(`#progress-${button.dataset.play}`);
button.addEventListener('click', function() {
const sound = resources[this.dataset.play].sound;
var plays = $$(`button[data-play]`);
for (var i = 0; i < plays.length; i++) {
plays[i].addEventListener('click', function() {
var progressBar = $(`#progress-${this.dataset.play}`);
var sound = resources[this.dataset.play].sound;
sound.filters = [stereo, equalizer, distort];
sound.singleInstance = singleInstance.checked;
sound.volume = parseFloat(volume.value);
sound.loop = !!this.dataset.loop;
sound.speed = parseFloat(speed.value);
const instance = sound.play();
instance.on('progress', (value) => {
var instance = sound.play();
instance.on('progress', function(value) {
progressBar.style.width = `${value * 100}%`;
});
instance.on('end', () => {
instance.on('end', function() {
progressBar.style.width = '';
});
});
}
});

const bands = $$('.eq');
for (let i = 0; i < bands.length; i++) {
const eq = bands[i];
var bands = $$('.eq');
for (var i = 0; i < bands.length; i++) {
var eq = bands[i];
eq.addEventListener('input', function() {
equalizer.setGain(PIXI.sound.filters.EqualizerFilter[this.id], parseFloat(this.value));
});
Expand All @@ -79,20 +77,20 @@ $('#globalVolume').addEventListener('input', function() {

$("#stop").addEventListener('click', function() {
PIXI.sound.stopAll();
const bars = $$('.progress-bar');
var bars = $$('.progress-bar');
for (var i = 0; i < bars.length; i++) {
bars[i].style.width = '';
}
});

$("#paused").addEventListener('click', function() {
const paused = PIXI.sound.context.paused = !PIXI.sound.context.paused;
var paused = PIXI.sound.context.paused = !PIXI.sound.context.paused;
this.className = this.className.replace(/\b(on|off)/g, '');
this.className += paused ? 'on' : 'off';
});

$("#muted").addEventListener('click', function() {
const muted = PIXI.sound.context.muted = !PIXI.sound.context.muted;
var muted = PIXI.sound.context.muted = !PIXI.sound.context.muted;
this.className = this.className.replace(/ (on|off)/g, ' ');
this.className += muted ? 'on' : 'off';
});
Expand Down
14 changes: 7 additions & 7 deletions examples/client/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

const $ = document.querySelector.bind(document);
const $$ = document.querySelectorAll.bind(document);
var $ = document.querySelector.bind(document);
var $$ = document.querySelectorAll.bind(document);

const autorun = $$('code[data-autorun]');
for (let i = 0; i < autorun.length; i++) {
var autorun = $$('code[data-autorun]');
for (var i = 0; i < autorun.length; i++) {
eval(autorun[i].innerHTML);
}

const buttons = $$('button[data-code]');
for (let i = 0; i < buttons.length; i++) {
const button = buttons[i];
var buttons = $$('button[data-code]');
for (var i = 0; i < buttons.length; i++) {
var button = buttons[i];
button.dataset.codeContent = $(button.dataset.code).innerHTML;
if (button.dataset.beforecode) {
button.dataset.beforecodeContent = $(button.dataset.beforecode).innerHTML;
Expand Down
22 changes: 11 additions & 11 deletions examples/client/sprites.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

const $ = document.querySelector.bind(document);
const $$ = document.querySelectorAll.bind(document);
var $ = document.querySelector.bind(document);
var $$ = document.querySelectorAll.bind(document);

const sprites = {
var sprites = {
'alien death': {
start: 1,
end: 2
Expand Down Expand Up @@ -40,21 +40,21 @@ const sprites = {
end: 19.3
}
};
let playhead = new PIXI.Graphics()
var playhead = new PIXI.Graphics()
.beginFill(0xff0000)
.drawRect(0, 0, 1, 100);
playhead.x = -1;
const sound = PIXI.sound.Sound.from({
var sound = PIXI.sound.Sound.from({
src: 'resources/sprite.mp3',
sprites: sprites,
singleInstance: true,
preload: true,
loaded: () => {
const app = new PIXI.Application(1024, 100, {
loaded: function() {
var app = new PIXI.Application(1024, 100, {
backgroundColor: 0xffffff,
view: document.getElementById('waveform')
});
const baseTexture = PIXI.sound.utils.render(sound, {
var baseTexture = PIXI.sound.utils.render(sound, {
width: 1024,
height: 100,
fill: '#ccc'
Expand All @@ -63,9 +63,9 @@ const sound = PIXI.sound.Sound.from({
}
});

const buttons = $$('button[data-sprite]');
for (let i = 0; i < buttons.length; i++) {
const button = buttons[i];
var buttons = $$('button[data-sprite]');
for (var i = 0; i < buttons.length; i++) {
var button = buttons[i];
button.addEventListener('click', function() {
sound.play(this.dataset.sprite).on('progress', function(value)
{
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
},
"homepage": "https://github.com/pixijs/pixi-sound#readme",
"devDependencies": {
"@types/node": "^8.0.0",
"browserify": "^14.0.0",
"electron": "^1.4.15",
"floss": "^2.0.1",
Expand Down
10 changes: 9 additions & 1 deletion src/SoundInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,15 @@ export default class SoundInstance extends PIXI.utils.EventEmitter
this._lastUpdate = this._now();
this._elapsed = start;
this._source.onended = this._onComplete.bind(this);
this._source.start(0, start, (end ? end - start : undefined));

if (end)
{
this._source.start(0, start, end - start);
}
else
{
this._source.start(0, start);
}

/**
* The sound is started.
Expand Down
2 changes: 1 addition & 1 deletion src/filters/EqualizerFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export default class EqualizerFilter extends Filter
const bands:BiquadFilterNode[] = equalizerBands.map(function (band:Band)
{
const filter:BiquadFilterNode = soundLibrary.context.audioContext.createBiquadFilter();
filter.type = band.type;
filter.type = band.type as BiquadFilterType;
filter.gain.value = band.gain;
filter.Q.value = 1;
filter.frequency.value = band.f;
Expand Down
Loading

0 comments on commit e367847

Please sign in to comment.