-
-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle complex properties + Promise API #26
Comments
HandleMPVPropertyChange should be improved to be able to return complex properties. Also it might be worth to implement
It requires changes to C++ plugin, sadly I don't have enough time currently to work on this project… |
I found a nifty workaround that is cross-platform, MPV supports IPC and this means with NET API we can actually set/get properties on the fly.
mp.set_property('input-ipc-server', '/mpvsocket')
import net from 'net'
import xpipe from 'xpipe'
export class Player extends React.PureComponent {
constructor (props) {
super(props)
// ...
// ...
// ...
setTimeout(() => {
const client = net.connect(xpipe.eq('/mpvsocket'), () => {
console.log('connected to IPC server')
const command = JSON.stringify(
{ 'command': ['observe_property', 1, 'track-list'], 'request_id': 100 }
)
client.write(Buffer.from(command + '\n'))
})
client.on('data', (res) => {
res = res.toString('utf8')
res = res.trim()
res = `[${res}]`
res = res.replace(/(\r\n|\n|\r)/g, ',')
res = JSON.parse(res)
res.forEach((key) => {
if (key.event === 'property-change' && key.name === 'track-list') {
if (key.data !== null) console.log(key.data)
}
})
})
}, 1000)
}
handleMPVReady (mpv) {
this.mpv = mpv
this.mpv.command('load-script', path.join(__dirname, 'script.js'))
// ...
}
} xpipe will return a cross-platform IPC path. this can be a temporary solution until someone improves the C++ plugin. |
You don't need
should work. Now need to implement proper handling of complex properties. |
currently there is no method for getting a property value like
mp.get_property
. sure there ismpv.observe
but it's not useful for some properties like track-listthe following code demonstrates why:
so in order to find out the number of subtitles that are available for the current file and then cycle through them first you have to find the number of tracks then observe each track individually like
this.mpv.observe('track-list/0/type')
.my workaround
since #24 is solved. I can load a custom script that uses
mp.get_property('track-list')
and then spawn PowerShell to write the result into a temporary file. and then withfs.watch
andfs.createReadStream
feed the result into renderer process.script.js
renderer.js
it is not an accurate solution because:
track-list
in my program.The text was updated successfully, but these errors were encountered: