62,614
社区成员
发帖
与我相关
我的任务
分享
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class Player2
{
//You'll have to edit these paths to something useful.
private static final String MPLAYER="/usr/bin/mplayer";
private static final String VIDEO_FILE ="/usr/A.rmvb";
private static Color wColor;
public static Process setFile(final File pFile, final int hWnd)
throws IOException
{
//final String[] lCmds = new String[] { MPLAYER, "-wid", String.valueOf(hWnd), "-nokeepaspect", "-x", "" + 352, "-y", "" + 240, "-geometry", "0:0", "-colorkey", "0x101010", "-vo", "directx", "-quiet", "-loop", "0", "-playlist", pFile.getAbsolutePath()};
final String[] lCmds = new String[] {
MPLAYER,
"-wid", String.valueOf(hWnd),
"-nokeepaspect",
"-geometry", "0:0",
"-colorkey", "0x101010",
"-vo", "directx",
pFile.getAbsolutePath()
};
/*
final String[] lCmds = new String[] {
MPLAYER,
"-wid", String.valueOf(hWnd),
pFile.getAbsolutePath()
};
***/
final Process lProcess = Runtime.getRuntime().exec(lCmds);
final InputStream stderr = lProcess.getErrorStream();
final InputStream stdin = lProcess.getInputStream();
new Thread(new Runnable() {
public void run() {
try {
final BufferedReader lReader = new BufferedReader(new InputStreamReader(stderr, "UTF-8"));
for (String l = lReader.readLine(); l != null; l = lReader.readLine()) {
System.out.println(l);
}
} catch (Throwable t) {
t.printStackTrace();
}
}
}).start();
new Thread(new Runnable() {
public void run() {
try {
final BufferedReader lReader = new BufferedReader(new InputStreamReader(stdin, "UTF-8"));
for (String l = lReader.readLine(); l != null; l = lReader.readLine()) {
System.out.println(l);
}
} catch (Throwable t) {
t.printStackTrace();
}
}
}).start();
return lProcess;
}
public static void main(String[] pArgs)
throws Exception
{
final Display wDisplay = new Display();
final Shell wShell = new Shell(wDisplay, SWT.SHELL_TRIM);
final Color bkColor = new Color(null,0x10,0x10,0x10);
final FillLayout wLayout = new FillLayout();
final Composite videoComposite;
videoComposite = new Composite(wShell, SWT.EMBEDDED);
videoComposite.setLayout(wLayout);
videoComposite.setBackground(bkColor);
videoComposite.setBounds(new Rectangle(0, 51, 720, 480));
wShell.setLayout(wLayout);
wShell.setSize(800, 600);
wShell.layout();
wShell.setVisible(true);
final Process lProcess = setFile(new File(VIDEO_FILE),
videoComposite.handle);
while ( !wShell.isDisposed() ) {
if ( !wDisplay.readAndDispatch() ) {
wDisplay.sleep();
}
}
lProcess.destroy();
}
}
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class Player2
{
//You'll have to edit these paths to something useful.
private static final String MPLAYER="/usr/bin/mplayer";
private static final String VIDEO_FILE ="/usr/A.rmvb";
public static Process setFile(final File pFile, final int hWnd)
throws IOException
{
//调用mplayer命令行
String[] cmd = new String[] {
MPLAYER,//mplayer路径
"-vo","x11",//linux下只能用x11和xv还有一个神码的,windows下用directX
"-identify", //输出详情
"-slave", //slave模式播放
"-wid", String.valueOf(hWnd),//视频窗口的 handle
"-colorkey", "0x010101",//视频窗口的背景色
"-osdlevel", String.valueOf(1),//osd样式
VIDEO_FILE//播放文件路径
};
final Process lProcess = Runtime.getRuntime().exec(cmd);
final InputStream stderr = lProcess.getErrorStream();
final InputStream stdin = lProcess.getInputStream();
new Thread(new Runnable() {
public void run() {
try {
final BufferedReader lReader = new BufferedReader(new InputStreamReader(stderr, "UTF-8"));
for (String l = lReader.readLine(); l != null; l = lReader.readLine()) {
System.out.println(l);
}
} catch (Throwable t) {
t.printStackTrace();
}
}
}).start();
new Thread(new Runnable() {
public void run() {
try {
final BufferedReader lReader = new BufferedReader(new InputStreamReader(stdin, "UTF-8"));
for (String l = lReader.readLine(); l != null; l = lReader.readLine()) {
System.out.println(l);
}
} catch (Throwable t) {
t.printStackTrace();
}
}
}).start();
return lProcess;
}
public static void main(String[] pArgs)
throws Exception
{
final Display wDisplay = new Display();
final Shell wShell = new Shell(wDisplay, SWT.SHELL_TRIM);
//在mplayer中你设置背景色为多少,在这里你就应该设置播放窗体的背景色为多少。
final Color bkColor = new Color(null,0x01,0x01,0x01);
final FillLayout wLayout = new FillLayout();
Composite videoComposite;
videoComposite = new Composite(wShell, SWT.EMBEDDED);
videoComposite.setLayout(wLayout);
videoComposite.setBackground(bkColor);
videoComposite.setBounds(new Rectangle(0, 51, 720, 480));
wShell.setLayout(wLayout);
wShell.setSize(800, 600);
wShell.layout();
wShell.setVisible(true);
int han=0;
//handle ,windows下使用.handle来获取窗体句柄。但是linux下使用embeddedHandle来获取句柄,否则会出现
/**
* X11 error: BadDrawable (invalid Pixmap or Window parameter)
* X11 error: BadWindow (invalid Window parameter)
* 这样的错误
*/
han=videoComposite.embeddedHandle;
System.out.println(han);
final Process lProcess = setFile(new File(VIDEO_FILE),
han);
while ( !wShell.isDisposed() ) {
if ( !wDisplay.readAndDispatch() ) {
wDisplay.sleep();
}
}
lProcess.destroy();
}
}