j-holub / Node-MPV

A NodeJs Module for MPV Player
https://www.npmjs.com/package/node-mpv
MIT License
116 stars 73 forks source link

Windows compatibility #14

Closed krabilousse closed 7 years ago

krabilousse commented 7 years ago

Hey,

If anyone is interested, I found a way to make this work on Windows. I tested with mpv 0.25.0 (build by lachs0r) on Windows 7. This is based on the official mpv doc about the option --input-ipc-server

On Windows, named pipes are used, so the path refers to the pipe namespace (\.\pipe\). If the \.\pipe\ prefix is missing, mpv will add it automatically before creating the pipe, so --input-ipc-server=/tmp/mpv-socket and --input-ipc-server=\.\pipe\tmp\mpv-socket are equivalent for IPC on Windows.

So, after a little bit of trial and error, this ended up working:

var mpv = require('node-mpv');
var mpvserver = mpv({socket:'\\\\.\\pipe\\mpvserver'})

Maybe node-mpv should have a working default socket path for Windows systems ?

j-holub commented 7 years ago

Hey there,

thanks for the info. Yes there should be something like that and I'm aware, that people have used this module before on Windows.

I don't have access to a Windows machine but I could try running it in a VM. No experience in developing with Windows at all though.

The global process variable seems to have a platform property storing information about the OS. Using this I should be able to detect wether node is running on Windows ore a Unix System and then setting the default socket.

Is there some convention on Windows where such sockets are usually created (like /tmp/ on Unix)? If not, what would you recommend, the directory the node project is located in?

krabilousse commented 7 years ago

Hey, I'm also not an expert on Windows specifcs either. According to this:

Named pipes cannot be mounted within a normal filesystem, unlike in Unix. Also unlike their Unix counterparts, named pipes are volatile (removed after the last reference to them is closed). Every pipe is placed in the root directory of the named pipe filesystem (NPFS), mounted under the special path \.\pipe\ (that is, a pipe named "foo" would have a full path name of \.\pipe\foo). Anonymous pipes used in pipelining are actually named pipes with a random name.

So, you can name it whatever, I guess.

j-holub commented 7 years ago

Thanks a lot! I'll boot up a Windows 7 or somethin' VM these days and see what I can do. This could actually really help out the Windows people.

j-holub commented 7 years ago

I recalled I could just use my girlfriends Surface Book (That's like Windows Windows) and try things out. It worked on her machine. I used a different syntax though and committed it on my MacBook. But I'm like 99.999% sure it works.

By default it sets the socket on Windows to exactly what you proposed and it worked. What didn't work on her machine was playing back links like youtube directly. Not sure if that's a Windows or Youtube-dl problem though.