Ilham Penta
Site menu
Section categories
My articles [6]
Java [14]
Java Programming
Flash [6]
Flash
URL web dan Tutorial [29]
Petualangan [1]
Our poll
Rate my site
Total of answers: 20
Statistics

Total online: 1
Guests: 1
Users: 0
Login form
Main » Articles » Java

Menggunakan JMF untuk file
Untuk menambahkan media berupa file video, maka kita harus memanggil library Java Media Framework.

berikut adalah contoh dari kode program

public class SebulPlayer extends javax.swing.JFrame {

/** Creates new form SebulPlayer */
public SebulPlayer() {
initComponents();
}

public void btnOpen() {
javax.swing.JFileChooser jFileChooser = new javax.swing.JFileChooser();

int buka = jFileChooser.showOpenDialog(null);

if (buka == jFileChooser.APPROVE_OPTION) {
java.net.URL fileURL = null;

try {
fileURL = jFileChooser.getSelectedFile().toURL();
}
catch (java.net.MalformedURLException mfue) {
System.err.println("Terjadi Exception berupa: MalformedURLException!");
}

if (fileURL != null) {
// Penggunaan Artikel Populer IlmuKomputer.Com
MediaPanel mediaPanel = new MediaPanel(fileURL);

this.getContentPane().remove(jTextArea1);
this.getContentPane().add(mediaPanel);
this.setSize(400, 400);
this.setVisible(true);
this.setResizable(true);
}
}
}

/***************************************************************/
//---------------------------- Class yang make JMF javax.media.
class MediaPanel extends javax.swing.JPanel {

public MediaPanel(java.net.URL mediaURL) {

setLayout(new java.awt.BorderLayout());

javax.media.Manager.setHint(javax.media.Manager.LIGHTWEIGHT_RENDERER, this);

try {

javax.media.Player mediaPlayer
= javax.media.Manager.createRealizedPlayer(mediaURL);
java.awt.Component video = mediaPlayer.getVisualComponent();
java.awt.Component controls = mediaPlayer.getControlPanelComponent();
if ( video != null )
add( video, java.awt.BorderLayout.CENTER );
if ( controls != null )
add( controls, java.awt.BorderLayout.SOUTH );
mediaPlayer.start();
}
catch ( javax.media.NoPlayerException noPlayerException )
{
System.err.println( "Terjadi Exception: NoPlayerException" );
}
catch ( javax.media.CannotRealizeException cannotRealizeException ) {
System.err.println( "Terjadi Exception: CannotRealizeException" );
}
catch ( java.io.IOException iOException ) {
System.err.println( "Terjadi Exception: iOException" );
}
}
} //---------------------------------------end class MediaPanel-----
/******************************************************************/


/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {//GEN-BEGIN:initComponents
jTextArea1 = new javax.swing.JTextArea();
jToolBar1 = new javax.swing.JToolBar();
jButton1 = new javax.swing.JButton();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jSeparator1 = new javax.swing.JSeparator();
jMenuItem2 = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
jMenuItem3 = new javax.swing.JMenuItem();
jSeparator2 = new javax.swing.JSeparator();
jMenuItem4 = new javax.swing.JMenuItem();

setTitle("SebulPlayer\u2122");
setResizable(false);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
} Artikel Populer IlmuKomputer.Com
Copyright © 2003 - 2006 IlmuKomputer.Com
4
});

jTextArea1.setEditable(false);
jTextArea1.setText("\nSelamat Datang di SebulPlayer\u2122\n\n Tugas EC5000\n
Teknologi Berorientasi Objek Menggunakan Java\n\n
Nama\t: Sigit Priyanggoro\n NIM\t: 13202020\n\n");
jTextArea1.setPreferredSize(new java.awt.Dimension(350, 150));
getContentPane().add(jTextArea1, java.awt.BorderLayout.CENTER);

jToolBar1.setPreferredSize(new java.awt.Dimension(1, 25));

//Tempatkan Icon folder open di sini
jButton1.setIcon(new javax.swing.ImageIcon("D:\\Forte\\images\\icon_open.gif"));
jButton1.setPreferredSize(new java.awt.Dimension(20, 20));
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jToolBar1.add(jButton1);

getContentPane().add(jToolBar1, java.awt.BorderLayout.NORTH);

jMenu1.setMnemonic('F');
jMenu1.setText("File");
jMenu1.setAutoscrolls(true);
jMenu1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenu1ActionPerformed(evt);
}
});

jMenuItem1.setMnemonic('O');
jMenuItem1.setText("Open");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});

jMenu1.add(jMenuItem1);

jMenu1.add(jSeparator1);

jMenuItem2.setMnemonic('x');
jMenuItem2.setText("Exit");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});

jMenu1.add(jMenuItem2);

jMenuBar1.add(jMenu1);

jMenu2.setMnemonic('b');
jMenu2.setText("About");
jMenu2.setAutoscrolls(true);
jMenuItem3.setMnemonic('S');
jMenuItem3.setText("SebulPlayer\u2122");
jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem3ActionPerformed(evt);
}
});

jMenu2.add(jMenuItem3);

jMenu2.add(jSeparator2);

jMenuItem4.setMnemonic('H'); Artikel Populer IlmuKomputer.Com

jMenuItem4.setText("Help");
jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem4ActionPerformed(evt);
}
});

jMenu2.add(jMenuItem4);

jMenuBar1.add(jMenu2);

setJMenuBar(jMenuBar1);

pack();
}//GEN-END:initComponents

private void jMenu1ActionPerformed(java.awt.event.ActionEvent evt) {
//GEN-FIRST:event_jMenu1ActionPerformed
// Add your handling code here:
}//GEN-LAST:event_jMenu1ActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
//GEN-FIRST:event_jButton1ActionPerformed
// Add your handling code here:
btnOpen();
}//GEN-LAST:event_jButton1ActionPerformed

private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {
//GEN-FIRST:event_jMenuItem4ActionPerformed
// Add your handling code here:
jTextArea1.setText("\n SEBULPLAYER\u2122 HELP\n\n 1. File > Open *utk
memainkan file*\n\n 2. File > Exit *utk keluar*");
}//GEN-LAST:event_jMenuItem4ActionPerformed

private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {
//GEN-FIRST:event_jMenuItem3ActionPerformed
// Add your hand ling code here:
jTextArea1.setText("\n ABOUT SEBULPLAYER\u2122\n\n
SebulPlayer\u2122 = sebuah almost-multi-media player biasa :D");
}//GEN-LAST:event_jMenuItem3ActionPerformed

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
//GEN-FIRST:event_jMenuItem1ActionPerformed
// Add your handling code here:
btnOpen();
}//GEN-LAST:event_jMenuItem1ActionPerformed

private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
//GEN-FIRST:event_jMenuItem2ActionPerformed
// Add your handling code here:
System.exit(0);
}//GEN-LAST:event_jMenuItem2ActionPerformed

/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
//GEN-FIRST:event_exitForm
System.exit(0);
}//GEN-LAST:event_exitForm

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
new SebulPlayer().show();
}


// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1; Artikel Populer IlmuKomputer.Com
Copyright © 2003 - 2006 IlmuKomputer.Com
6
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JMenuItem jMenuItem4;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JSeparator jSeparator2;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JToolBar jToolBar1;
// End of variables declaration//GEN-END:variables

}
Category: Java | Added by: penta (2010-09-29)
Views: 8735 | Comments: 3 | Tags: java, jmf, video java | Rating: 0.0/0
Total comments: 0
Name *:
Email *:
Code *:
Search
Site friends
  • Create a free website
  • Copyright Penta.Inc © Powered By: Senjapala