Skip to content
This repository has been archived by the owner on Jul 30, 2019. It is now read-only.

Commit

Permalink
Possible fix for iOS9 playback (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielku15 committed Feb 24, 2017
1 parent 937d0eb commit ca55fc6
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
14 changes: 14 additions & 0 deletions Build/JavaScript/AlphaSynth.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,20 @@ AlphaSynth.Main.AlphaSynthWebAudioOutput.prototype = {
this._circularBuffer = new AlphaSynth.Ds.CircularSampleBuffer(40960);
window.AudioContext = window.AudioContext || window.webkitAudioContext;
this._context = new AudioContext();
// possible fix for Web Audio in iOS 9 (issue #4)
var ctx = this._context;
if (ctx.state == "suspended"){
var resume = null;
resume = $CreateAnonymousDelegate(this, function (e){
ctx.resume();
window.setTimeout($CreateAnonymousDelegate(this, function (){
if (ctx.state == "running"){
document.body.removeEventListener("touchend", resume, false);
}
}), 0);
});
document.body.addEventListener("touchend", resume, false);
}
this._currentTime = 0;
// create an empty buffer source (silence)
this._buffer = this._context.createBuffer(2, 4096, this._context.sampleRate);
Expand Down
13 changes: 6 additions & 7 deletions Build/JavaScript/AlphaSynth.min.js

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions Source/AlphaSynth.JavaScript/Main/AlphaSynthWebAudioOutput.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using AlphaSynth.Ds;
using AlphaSynth.Player;
using AlphaSynth.Util;
using SharpKit.Html;
using SharpKit.Html.webaudio;
using SharpKit.JavaScript;
Expand Down Expand Up @@ -42,6 +43,25 @@ public void Open()
JsContext.JsCode("window.AudioContext = window.AudioContext || window.webkitAudioContext");
_context = new AudioContext();

// possible fix for Web Audio in iOS 9 (issue #4)
dynamic ctx = _context;
if (ctx.state == "suspended")
{
EventListener resume = null;
resume = e =>
{
ctx.resume();
HtmlContext.window.setTimeout(() =>
{
if (ctx.state == "running")
{
HtmlContext.document.body.removeEventListener("touchend", resume, false);
}
}, 0);
};
HtmlContext.document.body.addEventListener("touchend", resume, false);
}

_currentTime = 0;

// create an empty buffer source (silence)
Expand Down
14 changes: 14 additions & 0 deletions Source/AlphaSynth.JavaScript/res/AlphaSynth.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,20 @@ AlphaSynth.Main.AlphaSynthWebAudioOutput.prototype = {
this._circularBuffer = new AlphaSynth.Ds.CircularSampleBuffer(40960);
window.AudioContext = window.AudioContext || window.webkitAudioContext;
this._context = new AudioContext();
// possible fix for Web Audio in iOS 9 (issue #4)
var ctx = this._context;
if (ctx.state == "suspended"){
var resume = null;
resume = $CreateAnonymousDelegate(this, function (e){
ctx.resume();
window.setTimeout($CreateAnonymousDelegate(this, function (){
if (ctx.state == "running"){
document.body.removeEventListener("touchend", resume, false);
}
}), 0);
});
document.body.addEventListener("touchend", resume, false);
}
this._currentTime = 0;
// create an empty buffer source (silence)
this._buffer = this._context.createBuffer(2, 4096, this._context.sampleRate);
Expand Down

0 comments on commit ca55fc6

Please sign in to comment.