因为realplay在hardy中老core dump,所以装了个mplayer+win32codec,用来播放rmvb文件。但是却发现mplayer一个奇怪的问题:双击打开含中文名的rmvb文件时,mplayer会提示“failed to open file ****”,后面跟一个近似于乱码的一些由%分隔的字符串。但是直接拖放文件到mplayer窗口却能正常播放。而且如果右键编辑打开方式,手动添加一个mplayer的命令来打开rmvb文件,一切又正常。
这几天为了解决这个问题是煞费苦心啊……首先是找那个奇怪的字符串的意义。google加上咨询的结果是,这些字符串是URL规范中,对非ASCII码字符的一种转换(PHP中的urlencode()函数可以完成这个工作),相关的资料是RFC1738中2.2章节No corresponding graphic US-ASCII。
接着又找Gnome中与打开方式相关的资料。从这里了解到了Gnome的打开方式是每个MIME类型文件对应一个或几个.desktop文件。对比了一下手动添加打开方式和从列表中选择程序打开,两种方式对应的.desktop文件的异同,发现,系统默认的mplayer.desktop中,其中一行是Exe=gmplayer %U,而手动添加打开方式后,对应行的内容是Exe=gmplayer。猜测就是多了这个%U的参数导致了双击打开文件
一顿狂搜,让我找到了Linux Desktop Entry Specification,终于了解了那个%U的意义:自动将文件路径以URL方式编码后传递给程序本身。
所以解决这个问题的方法是:将/usr/share/applications/mplayer.desktop中,Exe=gmplayer %U修改成Exe=gmplayer %F。
附Exe项各种参数的意义(摘自这里):
| Code | Description |
|---|---|
%f |
A single file name, even if multiple files are selected. The system reading the desktop entry should recognize that the program in question cannot handle multiple file arguments, and it should should probably spawn and execute multiple copies of a program for each selected file if the program is not able to handle additional file arguments. If files are not on the local file system (i.e. are on HTTP or FTP locations), the files will be copied to the local file system and %f will be expanded to point at the temporary file. Used for programs that do not understand the URL syntax. |
%F |
A list of files. Use for apps that can open several local files at once. Each file is passed as a separate argument to the executable program. |
%u |
A single URL. Local files may either be passed as file: URLs or as file path. |
%U |
A list of URLs. Each URL is passed as a separate argument to the executable program. Local files may either be passed as file: URLs or as file path. |
%d |
Deprecated. |
%D |
Deprecated. |
%n |
Deprecated. |
%N |
Deprecated. |
%i |
The Icon key of the desktop entry expanded as two arguments, first –icon and then the value of the Icon key. Should not expand to any arguments if the Icon key is empty or missing. |
%c |
The translated name of the application as listed in the appropriate Name key in the desktop entry. |
%k |
The location of the desktop file as either a URI (if for example gotten from the vfolder system) or a local filename or empty if no location is known. |
%v |
Deprecated. |
%m |
Deprecated. |
P.S.顺便把双击视频文件打开vlc无法自动加载字幕的问题给解决了。解决方法同上,导致原因也同上,嗯嗯
如果你喜欢这篇日志的话,欢迎订阅我的RSS Feed!
本文来源于一阁Blog。版权所有,转载请确保已阅读该页面。


1 Response to “解决mplayer双击打开含中文名文件时的出错信息”