mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-02-21 06:29:02 +00:00
better workaround for autoplay audio in SampleAudio
This commit is contained in:
parent
9de22d6389
commit
9b65e79968
@ -24,6 +24,10 @@
|
||||
padding: 30px;
|
||||
background: #000;
|
||||
}
|
||||
.emuvideo:focus {
|
||||
outline:none;
|
||||
border-color:#888;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
|
||||
@ -54,6 +58,8 @@ if (window.location.host.endsWith('8bitworkshop.com')) {
|
||||
<script src="jsnes/dist/jsnes.min.js"></script>
|
||||
<script src="src/cpu/6809.js"></script>
|
||||
<script src="FileSaver.js/FileSaver.min.js"></script>
|
||||
<script src="lib/mousetrap.min.js"></script>
|
||||
<script src="lib/mousetrap-global-bind.min.js"></script>
|
||||
|
||||
<script>
|
||||
var exports = {};
|
||||
|
@ -501,9 +501,10 @@ if (window.location.host.endsWith('8bitworkshop.com')) {
|
||||
<script src="src/cpu/6809.js"></script>
|
||||
<!--<script src="jsnes/lib/dynamicaudio-min.js" type="text/javascript" charset="utf-8"></script>-->
|
||||
<script src="FileSaver.js/FileSaver.min.js"></script>
|
||||
<script src="localForage/dist/localforage.nopromises.js"></script>
|
||||
<script src="lib/mousetrap.min.js"></script>
|
||||
<script src="lib/mousetrap-global-bind.min.js"></script>
|
||||
<!-- UI-only stuff -->
|
||||
<script src="localForage/dist/localforage.nopromises.js"></script>
|
||||
<script src="lib/split.min.js"></script>
|
||||
|
||||
<script>
|
||||
|
@ -222,6 +222,6 @@ void main() {
|
||||
while (1) {
|
||||
if (!music_ptr) start_music(music1);
|
||||
play_music();
|
||||
delay(8);
|
||||
delay(15); // 30 msec delay
|
||||
}
|
||||
}
|
||||
|
20
src/audio.ts
20
src/audio.ts
@ -391,7 +391,8 @@ export var SampleAudio = function(clockfreq) {
|
||||
console.log("no web audio context");
|
||||
return;
|
||||
}
|
||||
self.context = new AudioContext();
|
||||
var ctx = new AudioContext();
|
||||
self.context = ctx;
|
||||
self.sr=self.context.sampleRate;
|
||||
self.bufferlen=2048;
|
||||
|
||||
@ -420,7 +421,16 @@ export var SampleAudio = function(clockfreq) {
|
||||
}
|
||||
|
||||
this.start = function() {
|
||||
if (!this.context) createContext();
|
||||
if (this.context) {
|
||||
// Chrome autoplay (https://goo.gl/7K7WLu)
|
||||
if (this.context.state == 'suspended') {
|
||||
this.context.resume();
|
||||
console.log('AudioContext should resume');
|
||||
}
|
||||
return; // already created
|
||||
}
|
||||
createContext(); // create it
|
||||
if (!this.context) return; // not created?
|
||||
sinc = this.sr * 1.0 / clockfreq;
|
||||
sfrac = 0;
|
||||
accum = 0;
|
||||
@ -434,8 +444,12 @@ export var SampleAudio = function(clockfreq) {
|
||||
}
|
||||
buffer = bufferlist[0];
|
||||
}
|
||||
|
||||
|
||||
this.stop = function() {
|
||||
this.context && this.context.suspend();
|
||||
}
|
||||
|
||||
this.close = function() {
|
||||
if (this.context) {
|
||||
this.context.close();
|
||||
this.context = null;
|
||||
|
@ -138,7 +138,9 @@ function startPlatform(qs) {
|
||||
// start recorder when click on canvas (TODO?)
|
||||
if (qs['rec']) {
|
||||
findPrimaryCanvas().on('focus', () => {
|
||||
if (!stateRecorder) { enableRecording(); }
|
||||
//if (!stateRecorder) { enableRecording(); }
|
||||
// toggle sound for browser autoplay
|
||||
platform.resume();
|
||||
});
|
||||
}
|
||||
var title = qs['n'] || 'Game';
|
||||
|
14
src/ui.ts
14
src/ui.ts
@ -746,7 +746,8 @@ function _revertFile(e) {
|
||||
});
|
||||
}, 'text')
|
||||
.fail(() => {
|
||||
alertError("Can only revert built-in files.");
|
||||
if (repo_id) alertError("Can only revert built-in examples. If you want to revert all files, You can pull from the repository.");
|
||||
else alertError("Can only revert built-in examples.");
|
||||
});
|
||||
} else {
|
||||
alertError("Cannot revert the active window. Please choose a text file.");
|
||||
@ -1731,12 +1732,17 @@ function addPageFocusHandlers() {
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: merge w/ embed.html somehow?
|
||||
function showInstructions() {
|
||||
var div = $(document).find(".emucontrols-" + getRootBasePlatform(platform_id));
|
||||
var vcanvas = $("#emulator").find("canvas");
|
||||
if (vcanvas) {
|
||||
vcanvas.on('focus', () => {
|
||||
if (platform.isRunning()) div.fadeIn(200);
|
||||
if (platform.isRunning()) {
|
||||
div.fadeIn(200);
|
||||
// toggle sound for browser autoplay
|
||||
platform.resume();
|
||||
}
|
||||
});
|
||||
vcanvas.on('blur', () => {
|
||||
div.fadeOut(200);
|
||||
@ -1751,7 +1757,7 @@ function installGAHooks() {
|
||||
gaEvent('menu', e.target.id);
|
||||
}
|
||||
});
|
||||
ga('send', 'pageview', location.pathname + '?platform=' + platform_id + '&file=' + qs['file'] + (repo_id?('&repo='+repo_id):''));
|
||||
ga('send', 'pageview', location.pathname+'?platform='+platform_id+(repo_id?('&repo='+repo_id):('&file='+qs['file'])));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1884,7 +1890,7 @@ export function startUI(loadplatform : boolean) {
|
||||
if (!platform_id) {
|
||||
platform_id = qs['platform'] = "vcs";
|
||||
}
|
||||
// lookup repository
|
||||
// lookup repository for this platform
|
||||
repo_id = qs['repo'] || (hasLocalStorage && localStorage.getItem("__lastrepo_" + platform_id));
|
||||
if (hasLocalStorage && repo_id && repo_id !== '/') {
|
||||
var repo = getRepos()[repo_id];
|
||||
|
Loading…
x
Reference in New Issue
Block a user