立即从VLC命令行播放信息 [英] Get Now Playing info from VLC command line

查看:65
本文介绍了立即从VLC命令行播放信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以从命令行中检索VLC的正在播放的信息(文件名,经过的时间等).

I want to know if it is possible to retrieve the now playing info (name of file, time elapsed, etc.) for VLC from the command line.

然后我想使用Java在某处使用此信息.

I want to then use Java to use this info somewhere.

一种可能是使用JNA,但不确定如何工作.

One possibility might be to use JNA, but not sure how that would work.

我到处搜索,但是它只告诉我如何从命令行启动文件.

I searched everywhere but it only tells me how to start a file from command line.

推荐答案

显然,VLC带有一个小型Http服务器,可用于向播放器发送命令.您可以通过发出%vlc -I http(--http-src/directory/--http-host host:port)来启动服务器,其中-http-src -http-host 是可选的.仅使用 vlc -I http VLC即可在系统上的 127.0.0.1:8080 上进行监听.

Apparently VLC comes with a small Http server which can be used to send commands to the player. You launch the server by issuing % vlc -I http (--http-src /directory/ --http-host host:port) where --http-src and --http-host are optional. Using just vlc -I http VLC listens on 127.0.0.1:8080 on my system.

然后您可以通过向 http://127.0.0.1:8080/requests/status.xml 发出GET请求来获取玩家状态和跟踪信息,该请求将返回一个如下所示的xml文件:

You can then retrieve player status and track information by issuing a GET request to http://127.0.0.1:8080/requests/status.xml, which returns an xml file that looks like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
...
<time>75</time>
<volume>512</volume>
<length>326</length>
<rate>1</rate>
...
<state>playing</state>
<position>0.23139409720898</position>
<information>
    <category name="meta">
        <info name="artwork_url">file:///path/to/art/work</info>
        <info name="genre">Genre</info>
        <info name="album">Album Name</info>
        <info name="publisher">Publisher</info>
        <info name="title">Track Title</info>
        <info name="track_number">1</info>
        <info name="filename">File Name</info>
        <info name="artist">Artist Name</info>
    </category>
    <category name="Stream 0">
        <info name="Bitrate">128 kb/s</info>
        <info name="Type">Audio</info>
        <info name="Channels">Stereo</info>
        <info name="Sample rate">44100 Hz</info>
        <info name="Codec">MPEG Audio layer 1/2/3 (mpga)</info>
    </category>
</information>
<stats>
...
</stats>
</root>

从音频文件中存在的标签中填充曲目信息的地方.

Where the track info is filled in from the tags present in the audio file.

您甚至可以使用此方法将命令发送到VLC以控制播放.这是完整的Http API参考: VLC Http请求.

You can even send commands to VLC to control playback using this method. Here is the full Http API reference: VLC Http Requests.

您可以使用Java可用的Http客户端之一与Http服务器进行交互,例如 Apache HttpClient ,您可以使用

You can interface with the Http server by using one of the Http clients available for Java, such as Apache HttpClient, and you can parse the xml returned from your requests using something like JAXP, though I'm sure that alternatives to both of these exist.

这篇关于立即从VLC命令行播放信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆