자바 호출 mplayer

java:
http://beradrian.wordpress.com/2008/01/30/jmplayer/
qt:
http://www.embedu.org/Column/Column140.htm
http://tingxx.ycool.com/post.2028303.html

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;

class LineRedirecter extends Thread {
    /** The input stream to read from. */
    private InputStream in;
    /** The output stream to write to. */
    private OutputStream out;

    /**
     * @param in the input stream to read from.
     * @param out the output stream to write to.
     * @param prefix the prefix used to prefix the lines when outputting to the logger.
     */
    LineRedirecter(InputStream in, OutputStream out) {
        this.in = in;
        this.out = out;
    }

    public void run()
    {
        try {
            // creates the decorating reader and writer
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            PrintStream printStream = new PrintStream(out);
            String line;

            // read line by line
            while ( (line = reader.readLine()) != null) {
                printStream.println(line);
            }
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;


public class MyPlayer {

	public static void main(String[] args) {
		try{
			
//		 create the piped streams where to redirect the standard output and error of MPlayer
//		 specify a bigger pipesize than the default of 1024
			PipedInputStream  readFrom = new PipedInputStream(256*1024);
			PipedOutputStream writeTo = new PipedOutputStream(readFrom);
			BufferedReader mplayerOutErr = new BufferedReader(new InputStreamReader(readFrom));
			Process mplayerProcess = Runtime.getRuntime().exec("e:/player.exe c:/media/video/1.mov");//-quiet -idle -slave  
//		 create the threads to redirect the standard output and error of MPlayer
			new LineRedirecter(mplayerProcess.getInputStream(), writeTo).start();
			new LineRedirecter(mplayerProcess.getErrorStream(), writeTo).start();
			
//		 the standard input of MPlayer
			PrintStream mplayerIn = new PrintStream(mplayerProcess.getOutputStream());

			mplayerIn.print("set_property time_pos 300");
			mplayerIn.print("
"); mplayerIn.flush(); mplayerIn.print("loadfile \"c:/media/video/1.mov\" 0"); mplayerIn.print("
"); mplayerIn.flush(); mplayerIn.print("pause"); mplayerIn.print("
"); mplayerIn.flush(); mplayerIn.print("get_property length"); mplayerIn.print("
"); mplayerIn.flush(); String answer; int totalTime = -1; try { while ((answer = mplayerOutErr.readLine()) != null) { if (answer.startsWith("ANS_length=")) { totalTime = Integer.parseInt(answer.substring("ANS_length=".length())); break; } } } catch (IOException e) { } System.out.println("========"+totalTime); try { mplayerProcess.waitFor(); } catch (InterruptedException e) {} }catch (Exception e) { } } }

예 를 들 어 windows 판 mplayer 입 니 다.이 예 는 기본 호출 입 니 다.필요 하 시 면 mplayer 매 뉴 얼 을 보 세 요.
http://wuzijingaip.iteye.com/admin/blogs/545229
자바 오픈 소스 만능 플레이어 의 한 단락


/*
 *   :[email protected]
 *   :http://hi.baidu.com/mqlayer
 */

package player;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.peer.ComponentPeer;

import javax.swing.JPanel;


public class VideoPanel extends JPanel{
	private static final long serialVersionUID = 4417214835406666167L;
	Player player;
	Canvas canvas;
	VideoPanel(Player pl){
		player=pl;
		setBackground(new Color(3,3,3));
		setLayout(new VideoLayout(player));
		canvas=new Canvas();
		add(canvas);
		canvas.setName("canvas");
		canvas.setBackground(new Color(3,3,3));
	}

	//     window handle
	@SuppressWarnings("deprecation")
	long getWid(){
		long wid=-1;
		try {
			Class<?> cl = Class.forName("sun.awt.windows.WComponentPeer");
			java.lang.reflect.Field f = cl.getDeclaredField("hwnd");
			f.setAccessible(true);
			ComponentPeer peer = canvas.getPeer();
			wid = f.getLong(peer);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("wid:" + wid );
		return wid;
	}
}





좋은 웹페이지 즐겨찾기