Mpv: JavaScript script is not working with error "Can't load unknown script"

Created on 4 Jan 2018  ·  7Comments  ·  Source: mpv-player/mpv

I followed the documentation to use JavaScript in plugins. But apparently that feature is not working. I use no configuration files and --script flag via command line couldn't work either. Also, Lua version of this script works okay.

mpv version and platform

macOS, HEAD https://github.com/mpv-player/mpv/commit/a9a4d6349a2d92200d80382532bff46971aafdae

Reproduction steps

  1. Create file ~/.config/mpv/scripts/test.js.
  2. Paste this inside that file.
    js function on_pause_change(name, value) { if (value == true) mp.set_property("fullscreen", "no"); } mp.observe_property("pause", "bool", on_pause_change);
  3. Close all mpv instances.
  4. Open a video and try functionality of script by pausing the video when fullscreen on.

Expected behavior

Script should perform its correct functionality.

Actual behavior

Script is not working.

Log file

[   0.041][v][cplayer] Can't load unknown script: /Users/Kutsan/.config/mpv/scripts/test.js

Most helpful comment

If you compile mpv yourself, then you first need to compile and install mujs:

git clone https://github.com/ccxvii/mujs.git
cd mujs
make release
sudo make install  # installs to /usr/local  . optionally add prefix=/path/to/elsewhere

and then compile mpv again.

All 7 comments

My guess is that your mpv build was not compiled with javascript support. You can check it by running:
mpv -v
and checking for javascript at the section List of enabled features: ....

@avih Yes, you are right; I can't find javascript there but how can I compile with JavaScript support? I couldn't have seen anything about JavaScript in docs.

If you compile mpv yourself, then you first need to compile and install mujs:

git clone https://github.com/ccxvii/mujs.git
cd mujs
make release
sudo make install  # installs to /usr/local  . optionally add prefix=/path/to/elsewhere

and then compile mpv again.

Thank you! I did and compiled with --enable-javascript flag and it works now!

compiled with --enable-javascript flag

That's optional. If mujs is installed and mpv can find it, then it will be enabled automatically.

Oh, I'll keep this in my mind.

For others, I created a PR https://github.com/Homebrew/homebrew-core/pull/22431 for Homebrew for macOS and it's accepted. If you are using macOS, all you need to do is:

brew install mpv

It installs MuJS and compiles with JavaScript support by default. Previously, this wasn't the case.

Note that, unofficial mpv bundle application at brew cask does not come with JavaScript support. So, you don't need that. Instead, this will do for native macOS application.

brew install mpv --with-bundle
brew link mpv
Was this page helpful?
0 / 5 - 0 ratings