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

Failed to restart and reconnect mpv instance the second time it crashes #7

Closed skyzh closed 7 years ago

skyzh commented 7 years ago

image

When I close mpv for the second time, it won't start again.

j-holub commented 7 years ago

Heyho,

so judging from the screenshot you're using Windows. I didn't even know this runs on Windows. I assume you set the socket yourself to make it according to Windows specifications, right?

Do you have any information on why MPV is crashing? And how does the socket behave on Windows, does it disappear if MPV crashes? Because on UNIX systems it just remains as a socket file.

Edit:

Could you please give me some information about which mpv version you are using? I remember having quite a similar Problem with version 0.18.1 .

skyzh commented 7 years ago

On Windows there is 'pipe' to take the place of UNIX socket on Linux. Mpv natively supports pipe. In my opinion, either there is something wrong with subprocess module which may not be able to detect crash of mpv, or the IPC interface cannot connect to pipe correctly if the pipe was closed for the first time. Further information will be provided later.

On Wed, Dec 14, 2016, 11:07 PM Jan Holub notifications@github.com wrote:

Heyho,

so judging from the screenshot you're using Windows. I didn't even know this runs on Windows. I assume you set the socket yourself to make it according to Windows specifications, right?

So do you have any information on why MPV is crashing? And how does the socket behave on Windows, does it disappear if MPV crashes? Because on UNIX systems it just stays there.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/00SteinsGate00/Node-MPV/issues/7#issuecomment-267057739, or mute the thread https://github.com/notifications/unsubscribe-auth/AEAPp0_ggIhIDCvgvUT-f7SBvj9YkGOmks5rIAZFgaJpZM4LNBPR .

skyzh commented 7 years ago
>mpv --version
mpv 0.22.0-git-1d4273c (C) 2000-2016 mpv/MPlayer/mplayer2 projects
 built on Sun Nov 20 18:59:12 CET 2016
ffmpeg library versions:
   libavutil       55.40.100
   libavcodec      57.66.105
   libavformat     57.58.100
   libswscale      4.3.101
   libavfilter     6.67.100
   libswresample   2.4.100
ffmpeg version: N-82573-ge7aaf0e

mpv behaves strange when I close it manually on Windows. As I close it when mpv is playing a video, there's a message that mpv has stopped working. Meanwhile the pipe connection isn't interrupted. Not until I click on Close program under that message does the connection is lost, and then mpv instance won't be restarted and connected.

image

Edited: when creating mpvplayer object, I set the option "socket": "\\\\.\\pipe\\mpvsocket".

j-holub commented 7 years ago

I haven't used Windows in about 5 years. I will install a Virtual Machine to investigate the problem.

Does the same thing happen, if you start mpv by hand (without node-mpv) and then close it (while playing a video)?

skyzh commented 7 years ago

mpv.js line 192

    this.mpvPlayer.on('close', function() {
        if(this.options.debug){
            console.log("MPV Player seems to have died. Restarting...");
        }

        // restart the mpv instance
        if(options.binary){
            this.mpvPlayer = spawn(options.binary, defaultArgs);
        }
        else{
            this.mpvPlayer = spawn('mpv', defaultArgs);
        }

        // TODO: reset ALL default parameters
        currentTimePos = null;
        // a small timeout is required to wait for mpv to have restarted
        // on weak machines this could take a while, thus 1000ms
        setTimeout(function() {
            // reobserve all observed properties
            // this will include those added by the user
            observeProperties();
            // observe timeposition
            this.socket.command("observe_property", [0, "time-pos"]);
        }.bind(this), 1000);
    }.bind(this));

When new mpvPlayer instance is created, the close event is not binded. Maybe that's why mpv won't restart the second time it is close or crashed?

skyzh commented 7 years ago

Fixed in #9

skyzh commented 7 years ago

Meanwhile, when I manually exit mpv instance spawned by node-mpv, it still crashes, and I have to kill the process in task manager.

j-holub commented 7 years ago

I already implemented a method to quit mpv player calling mpvPlayer.quit() in a local feature Branch. I'm still trying to find a good way to restart it again with something like mpvPlayer.restart() .