Programalama > JAVA - JSP

Etiketler: jmf, kullanarak, mediaplayer

Ort. 0
Puan ver:
import javax.media.*;
import com.sun.media.ui.*;
//import javax.media.protocol.*;
//import javax.media.protocol.DataSource;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import java.util.Vector;

public class MediaApplication extends Frame {


    public static void main(String args[]) {
	MediaApplication mdi = new MediaApplication();
    }

    static void Fatal(String s) {
	MessageBox mb = new MessageBox("JMF Hatasııı!", s);
    }    

    
    JMFrame jmframe = null;
    JDesktopPane desktop;
    FileDialog fd = null;
    CheckboxMenuItem cbAutoLoop = null;
    Player player = null;
    Player newPlayer = null;
    String filename;
    
    public MediaApplication() {
	super("Playerr");

	
	setLayout( new BorderLayout() );
	desktop = new JDesktopPane();
	desktop.setDoubleBuffered(true);
	add("Center", desktop);
	setMenuBar(createMenuBar());
	setSize(640, 480);
	setVisible(true);
	
	try {
	    UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
	} catch (Exception e) {
	    System.err.println("Metal Look and Feell olusturulamadı!");
	}
	addWindowListener( new WindowAdapter() {
	    public void windowClosing(WindowEvent we) {
		System.exit(0);
	    }
	} );

	Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, new Boolean(true));
    }
    
    private MenuBar createMenuBar() {
	ActionListener al = new ActionListener() {
		//tdundaralp@msn.com
	    public void actionPerformed(ActionEvent ae) {
		String command = ae.getActionCommand();
		if (command.equals("Ac")) {
		    if (fd == null) {
			fd = new FileDialog(MediaApplication.this, "Dosya Ac",
						       FileDialog.LOAD);
		//	fd.setDirectory("/videoClip");
		    }
		    fd.show();
		    if (fd.getFile() != null) {
			String filename = fd.getDirectory() + fd.getFile();
			openFile("file:" + filename);
		    }
		} else if (command.equals("Cikis")) {
		    dispose();
		    System.exit(0);
		}
	    }
	};

	MenuItem item;
	MenuBar mb = new MenuBar();
	
	Menu mnFile = new Menu("Dosya");
	mnFile.add(item = new MenuItem("Ac"));
	item.addActionListener(al);
	mnFile.add(item = new MenuItem("Cikis"));
	item.addActionListener(al);

	
	Menu mnOptions = new Menu("Seçeneker");
	cbAutoLoop = new CheckboxMenuItem("Suerkli Tekrar Et");
	cbAutoLoop.setState(true);
	mnOptions.add(cbAutoLoop);
	
	mb.add(mnFile);
	mb.add(mnOptions);
	return mb;
    }			

    
    public void openFile(String filename) {
	String mediaFile = filename;
	//author : Toygar Dundaralp
	Player player = null;

	URL url = null;
	try {
	  
	    if ((url = new URL(mediaFile)) == null) {
		Fatal("URL bulunamadı " + mediaFile);
		return;
	    }
	    
	  
	    try {
		player = Manager.createPlayer(url);
	    } catch (NoPlayerException e) {
		Fatal("Hata: " + e);
	    }
	} catch (MalformedURLException e) {
	    Fatal("Hata:" + e);
	} catch (IOException e) {
	    Fatal("Hata:" + e);
	}
	if (player != null) {
	    this.filename = filename;
	    JMFrame jmframe = new JMFrame(player, filename);
	    desktop.add(jmframe);
	}
    }
}

class JMFrame extends JInternalFrame implements ControllerListener {
    Player mplayer;
    Component visual = null;
    Component control = null;
    int videoWidth = 0;
    int videoHeight = 0;
    int controlHeight = 30;
    int insetWidth = 10;
    int insetHeight = 30;
    boolean firstTime = true;
    
    public JMFrame(Player player, String title) {
	super(title, true, true, true, true);
	getContentPane().setLayout( new BorderLayout() );
	setSize(320, 10);
	setLocation(50, 50);
	setVisible(true);
	mplayer = player;
	mplayer.addControllerListener((ControllerListener) this);
	mplayer.realize();
	addInternalFrameListener( new InternalFrameAdapter() {
	    public void internalFrameClosing(InternalFrameEvent ife) {
		mplayer.close();
	    }
	} );
		    
    }
    
    public void controllerUpdate(ControllerEvent ce) {
	if (ce instanceof RealizeCompleteEvent) {
	    mplayer.prefetch();
	} else if (ce instanceof PrefetchCompleteEvent) {
	    if (visual != null)
		return;
	    
	    if ((visual = mplayer.getVisualComponent()) != null) {
		Dimension size = visual.getPreferredSize();
		videoWidth = size.width;
		videoHeight = size.height;
		getContentPane().add("Center", visual);
	    } else
		videoWidth = 320;
	    if ((control = mplayer.getControlPanelComponent()) != null) {
		controlHeight = control.getPreferredSize().height;
		getContentPane().add("South", control);
	    }
	    setSize(videoWidth + insetWidth,
		    videoHeight + controlHeight + insetHeight);
	    validate();
	    mplayer.start();
	} else if (ce instanceof EndOfMediaEvent) {
	    mplayer.setMediaTime(new Time(0));
	    mplayer.start();
	}
    }
}


Yorumlar                 Yorum Yaz
Bu hazır kod'a ilk yorumu siz yapın!
KATEGORİLER
ASP - 240
ASP.NET - 24
C# - 75
C++ - 174
CGI - 8
DELPHI - 247
FLASH - 49
HTML - 536
PASCAL - 246
PERL - 11
PHP - 160
WML - 9
XML - 2
Copyright © 2002 - 2024 Hazır Kod - Tüm Hakları Saklıdır.
Siteden yararlanırken gizlilik ilkelerini okumanızı tavsiye ederiz.
hazirkod.com bir İSOBİL projesidir.