Giter Site home page Giter Site logo

node-mpv's People

Contributors

axelterizaki avatar dependabot[bot] avatar j-holub avatar jeffnappi avatar keysersoze1 avatar krtirtho avatar leonekmi avatar nolancassidy avatar p1100i avatar pussinboot avatar sir-kain avatar skyzh avatar vankasteelj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-mpv's Issues

Error handling

I did notice something strange, if I pass by mistake for example:

mpv.loadFile({filename: 'this.mkv', path:'foo/bar'})

it just fails without warning me of anything, it should state that it's unable to read the file

Windows errors

Hi,

I encountered an error on windows with your latest v2.

Two things from my debugging:

  1. lib/util.js has a typo on line 105: returnreject needs a space (also, returning is not necessary here as you don't have code it can do after the reject)

  2. lib/mpv/_startStop.js : for a reason (paths always have been a mystery to me), on line 35, you need to remove the enclosing " from the this.options.binary, otherwise it throws a ENOENT error

[question] can I hook into an existing mpv process?

Hi, wondering if I have already started mpv from the command line if there is a way to control that instance with this library

This would be for an IOT device where I would rather run this library as a daemon, controlling any and all mpv instances from behind the scenes

Is play() really completed once the video starts playing?

I know you have little time lately but I'm leaving it here for later.

One of the features we'd like to add to our karaoke player using node-mpv is to display the user's avatar in the lower right corner of the screen (the one who requested for a video to be played)

To do this, we need the video's width and height to properly place and resize the user's avatar on screen.

I'm still working on it but I'm having trouble getting a reliable information on width and height. On the first video I play, the results are correct, but on the second one, width and height are set to null. There are other properties I observed but all of them are null'd when I try to get them. I turned on verbose/debug on node-mpv and noticed these are indeed changed to null, but never changed back to the correct width/height

I'm thus not sure if it's a node-mpv or a mpv issue.

From what I gathered, width and height get populated with correct values once the first video frame has been decoded, hence why I was wondering if play() wasn't returning early or something like that, which means that I'd be trying to read width and height before they get set to the correct sizes...

It's a small feature we'd like to be added sometime in the future, but there's absolutely no hurry.

You might perhaps get a better understanding with trying out the app itself and see what it does. Whenever you have some time for this, ask me and we'll see via discord or IRC or whatever how to set up Karaoke Mugen and debug this together.

Thanks in advance :)

Using freeCommand() isn't working aka add a method to display ASS subitles

Hello.

I'm not sure if I'm doing it right or wrong, but I'm trying to write a command to mpv for sending text to the OSD during playback of a file.

I've first tried using the command function like this :

mpv.command('show-text',[message,duration,0]);

It worked fine, but then I wanted to position it and wanted to use ASS sequences. However, ASS is escaped since the ${osd-ass-cc/0} is not expanded. Apparently you use the mp.commandv method in mpv's API to send commands with this function. There's probably a good reason behind it and I'm not questioning that.

So I tried to use freeCommand() instead, and tried to set it up like that :

var command = { "command": ["show-text", "test", "10000", "0"] }
_player.freeCommand(command);

Alas, it's not displaying anything, even with the integers without double-quotes around them, I can't get any command to run, not even simple ones like "quit".

Am I doing something wrong with freeCommand?

Or could it be possible to have a command function that calls mp.command on mpv's API instead of mp.commandv ?

Thanks in advance :)

[v2] mpv stops randomly on start

When spawning a new player, sometimes (way to often, maybe 1/10) the load doesn't work.

mpv.start().then(() => {
   console.log('mpv started');
   return mpv.load('<my file>');
}).then(() => {
   console.log('file loaded');
});

The player does spawn, even the file is being read by MPV, yet the module fired a "stopped" event in between and the MPV binary is "free", your module doesnt have access to it.

The "stopped" event does occur after the console log "Connected to socket '\.\pipe\mpvserver'" though.

console.log() and unhandled rejections in console

Hello there :)

I just triggered a "bug" and saw there was quite a few console.log()s left in the code.

For example if my app launches mpv, but it gets closed by the user (by mistake for example by pressing the q key) and I attempt to call nodempv.quit() from my app, I get an uncaught rejection and it gets printed in the console, but isn't caught in my logging.

Until recently my app was running from a terminal and thus everything was being printed there, so it wasn't that much a big deal, but we're trying to move the app to Electron, thus eliminating all console.log output as much as possible :)

On a side-note, you left a console.log('fooo') in lib/mpv/mpv.js and it drives my beta-testers crazy :)

EDIT: I'm using the node-mpv-2 branch.

Pass additional parameters to load()

copy/paste from #30 :

To avoid big volume differences when going from one song to another in the playlist, we calculated audio gain through a ffmpeg script beforehand.

We need to pass the gain modifier to mpv when loading a video so it adjusts the volume accordingly.

The load() command in node-mpv doesn't offer any parameters other than append/replace. However, if you use command() this way...

_player.command('loadfile',[video,'replace','replaygain-fallback='+gain]);

We pass the loadfile mpv command manually to mpv, with the video path as first argument, replace, and then another option which is replaygan-fallback=, with an adjustment variable in decibels, like -5.04 for example.

I think the node-mpv load() function should allow to pass on additional parameters (other than append/replace).

Deprecate support for mpv below 0.17 ?

Hello.

I'm currently working on #33 (I'll submit a PR if I'm happy and if it works :p) because I'm going to need something like that for our project, and while looking through the code, I was wondering if it was still a good thing to support mpv below 0.17 in 2018.

It could remove a lot of code in the module, hence why I'm asking. No problem if you think it's still useful :)

Windows: you need to wrap path in quotes

I encountered issues with the module when trying to spawn MPV from C:\Program Files. At first I thought it was some kind of permission issue, Windows being weird with it's Program Files folder, but it turns out it was way dumber: the spaces in the path made the entire thing go south.

I'll PR a fix that shouldn't change anything for linux/osx, but make it more solid on Windows

percent-pos property is 'null' before quitting

Bug Description

When listening to 'statuschange' event and adding a 'percent-pos' property to observe, when quitting MPV, the percent-pos is set to 'null' on MPV > 0.29

How To Reproduce

let position = 0;

mpv.start().then(() => mpv.load(<myfile>)).then( () => mpv.observeProperty('percent-pos', 50));

mpv.on('statuschange', states => {
    position = states['percent-pos'];
    console.log(position); // Will display 0.01% up to 99.99%, no problem here
});

mpv.on('quit', () => console.log(position)) // Will display 'null' instead of the last percent-pos known, as it used to on 0.29
Software Versions
  • Node-Mpv: branch 2, commit 6fc6037 (latest at writing time)
  • MPV: 0.32.0 stable, windows build taken from the official recommended repository
Additional context

Might not be a node-mpv issue but a MPV issue? Trying to update from 0.29 has caused that problem mainly, afaik.

playlistRemove on last playlist item while playing kills MPV

Bug Description

If I'm in the middle of playing the final item of a playlist and I call playlistRemove, the mpv window is closed but node-mpv doesn't detect a quit, and there doesn't appear to be any way to restore mpv afterwards, besides restarting the node process.
If I then try to send a command to mpv via ipc I get 'property unavailable'.

I'm not sure if this is the expected behaviour of mpv, but if it is it should be handled better by node-mpv.

Software Versions
  • Node-Mpv: Version 2
  • MPV: mpv 0.31.0-67-g63bf362d11
Additional context

Anything else you might want to add

.load and multiple options

Hello :)

I'm not sure if it's a mpv bug or a node-mpv one, but here comes my issue :

I wanted to load a file (with the load method) with multiple options. When using just one option it works perfectly (For example ['replaygain-fallback=-10']) but if I add more options to that array, mpv doesn't load the file.

The options seem compatible as I can use them when lauching mpv from the command-line.

Options I wanted to add into the array for example :

options.push(`external-file=${defaultImageFile.replace(/\\/g,'/')}`);
options.push('force-window=yes');
options.push('image-display-duration=inf');
options.push('vid=1');

I haven't tested with command/freeCommand as I'm not too sure of how to format the thing properly though.

Any ideas?

getTimePosition returns wrong value after calling goToPosition more than once

Bug Description

After calling goToPosition more than once, getTimePosition returns wrong value

How To Reproduce

await mpv.start()
await mpv.load('test.flv')
await mpv.goToPosition(10)
console.log(await mpv.getTimePosition())
await mpv.goToPosition(20)
// await new Promise((resolve) => setTimeout(resolve, 1000))
console.log(await mpv.getTimePosition())

The output is

10
10

Though the expected output is

10
20

If you call getTimeposition after a while, the output is roughly correct

10
20.433 (roughly)
Software Versions
  • Node-Mpv: Node-MPV-2, commit b4e39d1 (latest when writing)
  • MPV: mpv-x86_64-20200308-git-28ea1ed from SourceForge
  • OS: Windows 10, x64, 10.0.18362

loop-playlist

Hi,

would it be possible to add the "loop-playlist" function?

Thank you very much!

Typescript

We talked about this a long time ago, and I had volunteered to help a bit with this particular issue, if you'd like.

I did look into it many months ago, and my main issue was that this would involve a more or less complete rewrite of the code to be typescript and modern JS-compliant.

It oculd take some time, but I do happen to have some free time now that we reached a big milestone with Karaoke Mugen (now powered by Electron)

If you're still interested, I can start working on it, but it'll be a all-or-nothing approach : as we can't just have parts in typescript and other parts in plain JS.

If you'd like to talk more about this via Discord, add AxelTerizaki#0001 there.

fyi for those running into unexpected crashes

mpv would refuse to start with this library for me more than half of the time
until i added --load-scripts=no to the command line options
autoload.lua does not play well with this : )

Playing with multiple instance of mpv

It looks like playing with multiple instance of mpv does not work well.

This simple example shows that connection to socket fails multiple time and then works suddenly.
Using the same example without specifying the socket, shows that the same mpv socket is used for different instance of the MPV object. This result in sound replaced randomly.

'use strict'
let mpv = require('node-mpv')

let mpvPlayer = new mpv({
  "verbose": true,
  "debug": true,  
  "audio_only": true,
  "socket": "/tmp/node-mpv-0.sock",
})

mpvPlayer.load("./assets/02.wav")
mpvPlayer.volume(70)
mpvPlayer.loop('inf')

setTimeout(()=>{
  let mpvPlayerB = new mpv({
    "verbose": true,
    "debug": true,
    "audio_only": true,
    "socket": "/tmp/node-mpv-1.sock",
  })

  mpvPlayerB.load("./assets/03.wav")
  mpvPlayerB.volume(70)
  mpvPlayerB.loop('inf')
}, 1000)

setTimeout(()=>{
  let mpvPlayerC = new mpv({
    "verbose": true,
    "debug": true,
    "audio_only": true,
    "socket": "/tmp/node-mpv-2.sock",
  })
  
  mpvPlayerC.load("./assets/04.wav")
  mpvPlayerC.volume(70)
  mpvPlayerC.loop('inf')
}, 2000)

'seek' event

How about something like mpv.on('seek', newPosition) ?

it's trivial to make, but there are 2 ways of doing it.

  1. There is the simple 'seek' event, you can add to your V2 /lib/mpv/_events.js, but I don't really see the point, because you can't attach anything to that event, the seek isnt done yet, MPV is just saying "hey i'm seeking, come back later to check where to":
                case "seek":
                    if(this.options.verbose){console.log("Event: seek")};
                    // emit seek event
                    this.emit("seek");
                    break;
  1. A more advanced seeking, emitting the new time position, but again, there is something I don't like, as it will emit statuschange at the same time (and it should, but it seems like an overkill of events).
            case "seek":
                if(this.options.verbose){console.log("Event: seek")};
                this.wasSeek = true;
                break;
            // observed properties
            case "property-change":
                // time position events are handled seperately
                if(message.name === "time-pos"){
                    // set the current time position
                    this.currentTimePos = message.data;
                }
                else{
                    // updates the observed value or adds it, if it was previously unobserved
                    this.observed[message.name] = message.data;
                    // emit a status change event
                    this.emit('statuschange', this.observed);
                    // output if verbose
                    if(this.options.verbose){
                        console.log("Event: statuschange");
                        console.log("Property change: " + message.name + " - " + message.data);
                    }
                }
                if (this.wasSeek){
                     this.emit("seek", this.currentTimePos);
                     this.wasSeek = false;
                }
                break;

There should be a third option, imho, but I can't seem to think of it.

stopped event not triggering on song end

Hello hello.

I know you're busy but when you're back into coding this I have a new issue for you.

I'm trying to find the right way to determine when mpv is at the end of a video. My main issue is that I'd like to trigger a player ending event on my app, but for that I need to know precisely when mpv has stopped playing.

The problem is that mpv is not triggering the "idle" message which means it has stopped. Instead it pauses at the end of the current video and emits a "pause" event that node-mpv catches. But a pause event isn't exactly what I'm looking for.

I also tried to play with the playback-remaining property, catching it between 1 and 0 seconds and ending the song there if it pauses, but alas, it's not as precise as I'd like...

If you've got any ideas on this, I'm all ears.

Launch fails if mpv is built from source

I think I've used mpv-build to build mpv.

mpv --version outputs this:

mpv git-2018-03-22-a04ac82 Copyright © 2000-2018 mpv/MPlayer/mplayer2 projects
 built on Fri Mar 23 22:46:33 UTC 2018

It fails at this line in util.js (regex match is null)

const match = (stdout.match(/(mpv) \d+.\d+.\d+/))[0];

handle manual closing of mpv

I'm trying to detect when MPV was manually closed by the user.

mpvPlayer.on(event) doesn't seem to work, I tried : close, closed, quit, quitted, end, ended

Is there a way to detect such a move? I see the mpv.js file is getting a new instance spawned, which is fine, but it'd be cool if there was a way to know what the user did

Windows compatibility

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<name>). 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 ?

mpv has just modified the version strings

1
I am using the latest mpv source code manually compiled the mpv executable file, and when node-mpv is loaded, it throws an error when it gets the version number of mpv application like this:

xxxx/node_modules/node-mpv/lib/util.js:41
				var end   = (output.match(/\(C\)/)).index;
				                                   ^

TypeError: Cannot read property 'index' of null
..................
..................

This mostly beacuse of the mpv version strings changed recently like this:

mpv 0.28.0-144-g0cd501d Copyright © 2000-2018 mpv/MPlayer/mplayer2 projects

And the previous version is still in this format:

mpv 0.26.0 (C) 2000-2017 mpv/MPlayer/mplayer2 projects

Link : mpv-player/mpv@49e704c

Wrong Player Version detected

Hi there,

I wanted to use your npm package in my new project. Apparently the code that detects the mpv version doesn't work with my build.

$ mpv --version
mpv git-0a81fe1 (C) 2000-2016 mpv/MPlayer/mplayer2 projects
 built on Mon Oct 17 15:49:16 UTC 2016
ffmpeg library versions:
   libavutil       55.32.100
   libavcodec      57.61.103
   libavformat     57.52.100
   libswscale      4.1.100
   libavfilter     6.64.100
   libswresample   2.2.100
ffmpeg version: N-82007-g1a9513b

I aquired this build using the debian buildscripts (used to create deb-packages) created by the mpv team. As you can see, there is no UNKNOWN in the version string. Therefore your lib is trying to find a major and a minor version for comparison.

The output.substring(start,end) will be '0a81fe1 (C) 2000' in this case. parseInt on that will fail on that.

I haven't actually installed your lib yet, but tried the detection script via node REPL. Starting mpv using the old parameter only issues a warning, so I think this will work fine. It would be nice for the library to handle this case (or having an option to override ipcCommand).

Thanks
Bernhard

Silent while loading url

Hi I have problem with play music, this is my code
var mpv = require('node-mpv'); var mpvPlayer = new mpv({ "audio_only": true, "binary": null, "debug": true, "verbose": true, }); mpvPlayer.load("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3");
version of my mpv:
mpv 0.14.0 (C) 2000-2015
I have silent and error, logs;
Lost connection to socket. Atemping to reconnect { Error: connect ENOENT /tmp/node-mpv.sock at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1170:14) errno: 'ENOENT', code: 'ENOENT', syscall: 'connect', address: '/tmp/node-mpv.sock' } Lost connection to socket. Atemping to reconnect { Error: connect ENOENT /tmp/node-mpv.sock at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1170:14) errno: 'ENOENT', code: 'ENOENT', syscall: 'connect', address: '/tmp/node-mpv.sock' } Lost connection to socket. Atemping to reconnect { Error: connect ENOENT /tmp/node-mpv.sock at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1170:14) errno: 'ENOENT', code: 'ENOENT', syscall: 'connect', address: '/tmp/node-mpv.sock' } Lost connection to socket. Atemping to reconnect { Error: connect ENOENT /tmp/node-mpv.sock at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1170:14) errno: 'ENOENT', code: 'ENOENT', syscall: 'connect', address: '/tmp/node-mpv.sock' } Lost connection to socket. Atemping to reconnect { Error: connect ENOENT /tmp/node-mpv.sock at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1170:14) errno: 'ENOENT', code: 'ENOENT', syscall: 'connect', address: '/tmp/node-mpv.sock' } Lost connection to socket. Atemping to reconnect
how I can fix it?

Not possible to setup a playlist from scratch (append) and play later?

Bug Description

I'd like to set up a playlist without playing it immediately.
But it seems I become a bit stuck when when I use mpv.load() with mode 'append' for the first item.
There doesn't appear to be a way to load and play the first item afterwards.
If I call mpv.getDuration(), I get an error 'property unavailable', so it's clear nothing is loaded.

mpv.play() doesn't do anything, setting the playlist-num to 0 results in an error, mpv.next() also gives an error.

After setting the playlist, presumably I can't use the load command with the first file as that would wipe the playlist.

I thought about using mode "replace" when loading the first playlist item and then quickly calling pause, but I don't want it to play for a millisecond.

It's very late in the evening and I'm a bit bleary eyed, so if the answer is painfully obvious I apologise.

EDIT: I should note I'm using the --o argument to output the video stream, I've just noticed that the behaviour is different without this argument. The playlist immediately plays and getDuration does not result in an error.
I suspect there's more likely an issue with the way mpv handles playlists than the node-mpv wrapper.

Software Versions
  • Node-Mpv: Version 2
  • MPV: mpv 0.31.0-67-g63bf362d11

unable to load a file

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

  • Windows 10
  • mpv 2017.07.01

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

mpv.load: "Cannot read property trim of undefined"

First of all, thanks for this work.

Now, to the issue.
I'm using v2 of this module and was trying to load url with mpv.load function and got unexpected behavior and error "Cannot read property trim of undefined". So, I took a look at source and there is check if that function was called via load() or append() for error handling purposes (here comes irony), done by regexp. So, I took a look at stackMatch variable and mine was [ 'mpv.load ', 'mpvLoad ' ]. mpvLoad is function written by me and from it I call mpv.load(url);

So, it seems that split('.')[1].trim() is not the best way to check caller or may be you should change regexp(I'm not strong in it).

[node-mpv-2] Loading subtitles after loading and playing a file

With the 1.3 version, here's the code I use to load a file, play it, and add subtitles :

module.exports._player is an instance of node-mpv

module.exports._player.command('loadfile',[video,'replace','replaygain-fallback='+gain]);			
module.exports._player.play();
var timeout = 1500;
setTimeout(function(){
   module.exports._player.addSubtitles('memory://'+subtitle);						
},timeout);

I have to do it this way because the video file takes a bit of time to load. if I don't use a setTimeout, in some cases the subtitles are loaded before the video plays, and thus don't display at all on screen.

In version 2, I'd need the new options parameter added to load() in 1.4 to be able to use the function and its new promsified version.

I could write something like this :

module.exports._player.load(...)
  .then(() => {
     module.exports._player.play();
     var timeout = 1500;
     setTimeout(function(){
        module.exports._player.addSubtitles('memory://'+subtitle);						
     },timeout);
  });

The thing is, I cannot tell if what takes time is the load() function or the play() function. In any case, I think play() should be promsified, so I can add subtitles right after play() returns a promise.
I could then get rid of the timeout and achieve something like this :

module.exports._player.load(...)
  .then(() => {
     module.exports._player.play()
  .then(() => {
     module.exports._player.addSubtitles('memory://'+subtitle);						
  });
  });

Could it be possible to have the improvements from 1.4 ported to 2.0, at least the options argument of load() which would allow me to use it instead of command() ? Also, have play() return a promise ?

Having command() and freeCommand() return a promise could be helpful as well, I believe.

As for other promised functions, the problem is that I can't think of many use cases where some of them should be promsified. On the other hand, having only some functions returning promises and not others could be quite confusing. I realize it's a lot of code to add especially given all the functions in mpv. To me, a first step would be to add play(), command() and freeCommand() and see if other people might find it interesting to add other promsified functions :)

Can't connect to socket.

Lost connection to socket. Atemping to reconnect
{ Error: connect ENOENT /tmp/node-mpv.sock
    at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1082:14)
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'connect',
  address: '/tmp/node-mpv.sock' }
Lost connection to socket. Atemping to reconnect
{ Error: connect ENOENT /tmp/node-mpv.sock
    at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1082:14)
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'connect',
  address: '/tmp/node-mpv.sock' }
Lost connection to socket. Atemping to reconnect
root@vps7170:/home/notifyBot# mpv --version
mpv 0.14.0 (C) 2000-2015 mpv/MPlayer/mplayer2 projects
 built on UNKNOWN
ffmpeg library versions:
   libavutil       54.31.100
   libavcodec      56.60.100
   libavformat     56.40.101
   libswscale      3.1.101
   libavfilter     5.40.101
   libswresample   1.2.101
ffmpeg version: 2.8.15-0ubuntu0.16.04.1

I only have this in my code:

const mpvAPI = require('node-mpv');
const mpv = new mpvAPI({"debug": true});

[Node-MPV-2] addSubtitles and rejected promises

Hello.

Not sure if you'll be able to reproduce this but here goes.

While testing out Karaoke Mugen's database I stumbled on a corrupted ASS file (most likely) which does not load in mpv when I run the addSubtitles command. Thanks to your error handling I got ontified on the error.

Here's my code :

if (subFile) try {
  await player.addSubtitles(subFile);
} catch(err) {
  logger.error(`[Player] Unable to load subtitles : ${err}`);
}

I added the try/catch because I received an unhandled rejection on this particular command when using that ass file.

However, the try/catch doesn't seem to work and I still get an unhandled rejection 👍

12:49:44 - info: [Engine] Playing Kaizoku Ôji - Kaizoku Ôji
Unhandled Rejection at: Promise Promise {
  <rejected> { errcode: 3,
  verbose: 'ipcCommand invalid',
  method: 'addSubtitles()',
  arguments:
   [ 'D:\\dev\\karaokemugen-app\\app\\data\\lyrics\\JAP - Kaizoku Ouji - OP - Kaizoku Ouji.ass' ],
  errmessage: 'error running command' } } reason: { errcode: 3,
  verbose: 'ipcCommand invalid',
  method: 'addSubtitles()',
  arguments:
   [ 'D:\\dev\\karaokemugen-app\\app\\data\\lyrics\\JAP - Kaizoku Ouji - OP - Kaizoku Ouji.ass' ],
  errmessage: 'error running command' }

I'm attaching the ass file so you can try it out on any video. (had to rename it to txt so it would get accepted by github)
JAP - Kaizoku Ouji - OP - Kaizoku Ouji.txt

I'm running mpv 0.27.0

Not sure if it's a bug on my end or on yours, tell me if you're able to reproduce it?

Thanks in advance.

spawn arg --o=- prevents start() from resolving.

Bug Description

I'm trying to output to a file or a pipe using --o=- and it doesn't work.
mpv.start() never resolves, as a result any method results in 'MPV is not running' errors.

I had a look at the source code and quickly realised it's due to the way node-mpv checks for the 'Listening to IPC socket'.
When --o is piping to stdout, mpv uses stderr for messages.

This is quite easily fixed by checking both stderr and stdout for the IPC Socket messages.

Software Versions
  • Node-Mpv: Version 2
  • MPV: mpv 0.31.0-67-g63bf362d11

Maintainer?

Hello there, it's me again.

I've seen there has been close to no activity on the project for a bit.
Do you need help maintaining the project? I could merge the PRs I made and release version 2 for you and keep it living.

We've been using node-mpv for a while for Karaoke Mugen, and it proved to be quite stable so far. I could even write some more docs with concrete examples of what can be acheived.

Hope everything's going well for you.

Make MPV top-level

Hi, is there a way to make MPV be on top again? I see in the docs there is a '--ontop', but I cannot seem to use that to control MPV and make it go "on top of" my JS app

Could dependency cuid be replaced by a smaller one like uuid?

Hello again :)

I'm trying to reduce my node_modules footprint and stumbled upon node-mpv's dependency cuid, which seems to be used to generate collision-free request IDs.

I'm not sure if the likeness of a collision when generating IDs is high or not in the case of node-mpv, but the cuid module is about 2,2Mb big.

Is it a big requirement, or could it be replaced with a smaller ID generator like uuid or randomstring ?

I could submit a pull request if you'd be okay with this.

Changing the statuschange behaviour to single messages per change

Hey guys,

in #68 @hedgehog90 proposed another status change event, that he called statuschange_single, that triggers a message about a single status change whenever one happens.

At the moment there's this big status change object that looks something like this, just populated with even more properties

{
  "mute": false,
  "duration": 320,
   "media-title": "somesong"
}

and if there's a change to one single of those properties, the statuschange event returns the whole object, which could possibly have like 50 properties.

Instead of introducing statuschange_single I'm rather leaning towards replacing the old one with the new behaviour, that would return something like this

{
   "property": "duration",
   "value": 400
}

Of course, this would break the API. But since we're doing a Version 2 here anyways, which means breaking the API is kind of okay, since people migrating from Version 1 to Version 2 will have to migrate their code anyways.

What do you guys think? @vankasteelj , @AxelTerizaki and @hedgehog90. You guys seem to be the most active user of this package.

Jumping in and out of fullscreen

I have a strange issue where mpv seems to be jumping in and out of fullscreen. Every other video will play in a window. If i hit escape while in the window it'll jump back into fullscreen though. Im unsure if this is just mpv or a wrong status being send to mpv.

This is my code. Im trying to create a watch folder that the player should loop through over and over. This is running on a Mac 10.11

let mpv = require('node-mpv');
let chokidar = require('chokidar');

let watchfolder = 'watchfolder/*';
let watcher = chokidar.watch(watchfolder, {
  ignored: /(^|[\/\\])\../
});
let player = new mpv();

let current = 0;
let playlist = []

watcher.on('add', file => {
  playlist.push(file);
});

watcher.on('unlink', file => {
  playlist = playlist.filter(item => item !== file);
});

player.on('stopped', () => {
  if (current >= playlist.length)
    current = 0;

  player.loadFile(playlist[current]);
  player.fullscreen();
  player.mute();
  console.log('Playling: ', current, playlist.length, playlist[current]);
  current++;
});

Use promises for getProperty

This would make it a bit easier to use:

let trackCount = await mpv.getProperty("playlist/count");
console.log(trackCount, "tracks in playlist!");

– or –

mpv.getProperty("playlist/count").then((trackCount) => {
  console.log(trackCount, "tracks in playlist!");
});

More info on Promises

Multiple call of start (Node-MPV-2)

Hi,

I am using Node-MPV-2, and I have a few questions.

Several functions does not work if the player is not running. For instance: quit, resume, pause, and load (non-exhausive list). Should Node-MPV-2 be more resilient and checks if isRunning is true, or it should be on my side ? Load even breaks node
sh Error: connect ECONNREFUSED /tmp/node-mpv.sock at Object.exports._errnoException (util.js:1020:11) at exports._exceptionWithHostPort (util.js:1043:20) at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1086:14) [19:53:58] [nodemon] app crashed - waiting for file changes before starting...
Actually, I came here for a derivation of this issue. If we call several times start method, it will spawn a new mpv process each time, and replace the old one in the mpvPlayer object.
Hence, if you do something like:

START -> LOAD a file -> START -> QUIT
You will quit the second START, and the other one will be still there and unreferenced.

Thank you for your work, it is really a useful project !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.