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

unable to load a file #15

Closed vankasteelj closed 7 years ago

vankasteelj commented 7 years ago

Hi, I'm trying out your api wrapper, but I can't seem to make it load anything. The player doesn't even open.

Here's the code :

    let mpv = require('node-mpv');
    let mpvPlayer = new mpv({
        binary: "C:\\Users\\vanka\\Desktop\\mpv\\mpv.exe"
    },
    [
        "--no-config",
        "--load-scripts=no"
    ]);
    mpvPlayer.loadFile('/test/file.mkv');
    mpvPlayer.on('statuschange', status => console.log(status));
    mpvPlayer.on('stopped', () => console.log('stopped'));

And here's the console output : nw_2017-07-03_14-49-37

The file can be read by mpv, it works fine when using outside the js env, with clicking and drag&dropping and other boring stuff

vankasteelj commented 7 years ago

Ok I found the problem. The missing "path" in the status object got me in the right way : I must use absolute paths, all the time, nothing relative.

Maybe that's worth adding in the docs, like changing:

mpvPlayer.loadFile("/path/to/your/favorite/song.mp3");

to

mpvPlayer.loadFile("/absolute/path/to/your/favorite/song.mp3");

j-holub commented 7 years ago

Heyho :)

Where do you have to use absolute paths? To load the file? I always used relative paths so far and that worked just fine.

The problem could be, that your path starts with a /. That refers to the linux root directory. As a relative path it would either be test/file.mkv or ./test/file.mkv. But since you're on Windows, shouldn't it be test\file.mkv anyway? (sorry I don't have much of a clue about Windows)

It says in the docs Provides the absolute path to the file or the full url of a stream by the way.

vankasteelj commented 7 years ago

I must have misread then. On windows with node, you usually use / or \\

j-holub commented 7 years ago

I see thanks for the info. It should really work with relative paths thought. On MacOS and Linux it does at least. Have you tried with test/file.mkv instead of /test/file.mkv?

The statusobject will always give you the absolute path, but you should be able to insert a relative one.

vankasteelj commented 7 years ago

apparently I can't, my snippet is located in <appfolder>/app/main.html (nwjs app), and the video file is <appfolder>/app/test/file.mkv

edit: ok, somehow it decides that the PWD is <appfolder> for no obvious reason.

so mpvPlayer.loadFile('app/test/file.mkv'); does work

j-holub commented 7 years ago

Glad it works for you.

On Unix you can go up one directory by using ... Thus ../../foo/bar would go two directory up and then enter foo and bar. Might work on Windows, too.

vankasteelj commented 7 years ago

It works that way too, but it's buggy sometimes. Windows is a pain, but it also has directx and i'm too lazy to reboot everytime, so I end up using Windows most of the time

I think here the issue is more with nwjs, but why would it sometimes chose the actual file as PWD, sometimes the app root, that I don't know