前段时间做过qt内嵌mplayer的一个小程序,感觉mplayer还行不过不支持打开图片感觉有点无力。话不多说上代码:
QString path="d:/1.mkv";
QWidget *vw=new QWidget(this);
vw->resize(400,300);
QString common = "E:/testmplayer/debug/mplayer/MPlayer.exe -slave -quiet -vo direct3d -wid " + QString::number(reinterpret_cast<qlonglong>(vw->winId())) + " "+ (path);
process=new QProcess();
process->start(common);
这样一个小的播放器就做好了,通过命令方式启动 myplayer.exe 其中 -slave就是用后台命令控制的意思
process->write("xxx \n"); //xxx为操作指令必须要有\n
在mplayer官网上,可以看到下面的命令:
-------------------
The -slave option switches on slave mode, in which MPlayer works as a backend
for other programs. Instead of intercepting keyboard events, MPlayer will read
commands separated by a newline (\n) from stdin.
To try slave mode out by hand, run
mplayer -slave -quiet <movie>
and type slave commands into the console window.
You can also use a fifo file (named pipe):
mkfifo </tmp/fifofile>
mplayer -slave -input file=</tmp/fifofile> <movie>
Most slave mode commands are equivalent to command line options, though not
necessarily under the same name. Detailed descriptions can be found in the
man page.
All commands can be prefixed with one of "pausing ", "pausing_keep ", or
"pausing_toggle ". "pausing " tells MPlayer to pause as soon as possible
after processing the command. "pausing_keep " tells MPlayer to do so only if
it was already in paused mode. "pausing_toggle " tells MPlayer to do so
only if it was not already in paused mode. Please note that "as soon as
possible" can be before the command is fully executed.
As a temporary hack, there is also the _experimental_ "pausing_keep_force "
prefix, with which MPlayer will not exit the pause loop at all.
Like this you can avoid the "frame stepping" effect of "pausing_keep "
but most commands will either not work at all or behave in unexpected ways.
For "set_mouse_pos" and "key_down_event", "pausing_keep_force" is the default
since other values do not make much sense for them.
Various tips and tricks (please help expand it!):
- Try using something like
pausing_keep_force pt_step 1
get_property pause
to switch to the next file. It avoids audio playback starting to play
the old file for a short time before switching to the new one.
- To ensure the user can't control MPlayer "behind your back" use
something like -input nodefault-bindings -noconfig all
Available commands ('mplayer -input cmdlist' will print a list):
af_add <filter_arguments_list> (comma separated list of audio filters with parameters)
(experimental) Load the given list of audio filters.
af_clr
(experimental) Unload all loaded audio filters.
af_cmdline <filter_name> <filter_arguments>
(experimental) Send new command-line options to a filter with the given name.
af_del <filter_name_list> (comma separated list of audio filter's names)
(experimental) Unload the first occurrence of the filters, if loaded.
af_switch <filter_arguments_list> (comma separated list of audio filters with parameters)
(experimental) Remove all the audio filters and replace them with the given list.
alt_src_step <value> (ASX playlist only)
When more than one source is available it selects the next/previous one.
audio_delay <value> [abs]
Set/adjust the audio delay.
If [abs] is not given or is zero, adjust the delay by <value> seconds.
If [abs] is nonzero, set the delay to <value> seconds.
[brightness|contrast|gamma|hue|saturation] <value> [abs]
Set/adjust video parameters.
If [abs] is not given or is zero, modifies parameter by <value>.
If [abs] is non-zero, parameter is set to <value>.
<value> is in the range [-100, 100].
capturing [value]
Toggle/set capturing the primary stream like -dumpstream.
Requires the -capture parameter to be given.
change_rectangle <val1> <val2>
Change the position of the rectangle filter rectangle.
<val1>
Must be one of the following:
0 = width
1 = height
2 = x position
3 = y position
<val2>
If <val1> is 0 or 1:
Integer amount to add/subtract from the width/height.
Positive values add to width/height and negative values
subtract from it.
If <v