feross / timidity

Play MIDI files in the browser w/ Web Audio, WebAssembly, and libtimidity
https://bitmidi.com
MIT License
368 stars 38 forks source link

IOS background audio #10

Closed rick-li closed 4 years ago

rick-li commented 4 years ago

Hey @feross, I love this plugin, finally i can add midi player to my site. so far it works for desktop browsers. However on iphone/ipad, as soon as i switch to a different tab/page, or turn off screen, the audio stopped. but it seem to work perfectly in your bitmidi.com, even i switch to other app or turn off screen. Here's my sample code. Is there anything i should do to keep the audio playing in the background ?

test link

  const Timidity = require('timidity')
  const player = new Timidity()
 window.onload = function(){
    document.querySelector("#start_music").addEventListener('click',function(){
        console.log('started.');
        player.load('/bach.mid')
        player.play()
    });
    document.querySelector("#stop_music").addEventListener('click',function(){
        console.log('Stopped.');
        player.pause();

    });
  }
rick-li commented 4 years ago

I found it looks like https://github.com/feross/unmute-ios-audio does the trick.