electron / electron

:electron: Build cross-platform desktop apps with JavaScript, HTML, and CSS
https://electronjs.org
MIT License
112.94k stars 15.16k forks source link

MIDI access cannot be init first time unless reload #2821

Closed wildfiremedia closed 8 years ago

wildfiremedia commented 8 years ago

Critical fix need for this issue on Windows, tested on 8/8.1 that can't properly initial midi port the first time Electron is run, it could only properly initialize after reload the page using remote.getCurrentWindow().reload()

All of these error have been tested exhaustively and conclude it's a bug.

var midi = null;  // global MIDIAccess object
var output = null;

function echoMIDIMessage( event ) {
  if (output) {
    output.send( event.data, event.timestamp );
  }
}

function onMIDISuccess( midiAccess ) {
  console.log( "MIDI ready!" );
//  var input = midiAccess.inputs.entries.next();
 // if (input)
 //   input.onmidimessage = echoMIDIMessage;
  output = midiAccess.outputs.values().next().value;
  if (!output)
    console.log("Uh oh! Couldn't get i/o ports.");
}

function onMIDIFailure(msg) {
  console.log( "Failed to get MIDI access - " + msg );
}

navigator.requestMIDIAccess().then( onMIDISuccess, onMIDIFailure );
zcbenz commented 8 years ago

Which version of Electron are you using? I got following output but I think it is because I don't have MIDI devices:

MIDI ready!
Uh oh! Couldn't get i/o ports.

Also can you try if it works in Chrome?

wildfiremedia commented 8 years ago

The Uh oh! Couldn't get i/o ports. can mean 2 things, either there is no ports or the port open at the wrong steps/lifecycle.

I tried on latest Electron and Google chrome web browser with the same issue that tell me either V8 or W8.x have issue. I tried W7 early this year was fine. Note, I didn't have any firewalls or antivirus installed.

You can install any supported Virtual Midi e.g. LoopBe1, the output api from webmidi will show blank results, if we load the page, the device will appear. There is no race conditions from user end, I assume there might be a bug in V8 implementation.

On Friday, September 18, 2015, Cheng Zhao notifications@github.com wrote:

Which version of Electron are you using? I got following output but I think it is because I don't have MIDI devices:

MIDI ready! Uh oh! Couldn't get i/o ports.

Also can you try if it works in Chrome?

— Reply to this email directly or view it on GitHub https://github.com/atom/electron/issues/2821#issuecomment-141333667.

zcbenz commented 8 years ago

If it doesn't work in Chrome browser you should report it to Chromium's issues tracker instead, we are not able to fix it on Electron's side.

proyb2 commented 8 years ago

Updated Electron with Nodejs 4.1.1 works now.