Pergunta

I am currently using netbeans and i have downloaded the JMF plug in using its own plug in finder.I found one of the codes for video streaming using JMF from the net .The 'import javax.media.player' shows an error that package javax.media does not exists. Please help me in this matter as soon as possible.I am a beginner so a possible coding would be appreciated.

import java.awt.BorderLayout;
 import java.awt.Component;
 import java.io.IOException;
 import java.net.URL;
 import javax.media.CannotRealizeException;
 import javax.media.Manager;
 import javax.media.NoPlayerException;
 import javax.media.Player;
 import javax.swing.JPanel;



import javax.management.*;


public class MediaPlayer extends JPanel {

    public MediaPlayer() {
         setLayout( new BorderLayout() ); // use a BorderLayout

             // Use lightweight components for Swing compatibility
     Manager.setHint( Manager.LIGHTWEIGHT_RENDERER, true );

             try
             {
                 // create a player to play the media specified in the URL
                 Player mediaPlayer = Manager.createRealizedPlayer("E:\\FFOutput\\Bollywood");

                 // get the components for the video and the playback controls
                 Component video = mediaPlayer.getVisualComponent();
                 Component controls = mediaPlayer.getControlPanelComponent();

                 if ( video != null )
                 add( video, BorderLayout.CENTER ); // add video component

                 if ( controls != null )
                 add( controls, BorderLayout.SOUTH ); // add controls

                 mediaPlayer.start(); // start playing the media clip
             } // end try
             catch ( NoPlayerException noPlayerException )
             {
                 System.err.println( "No media player found" );
             } // end catch

    }
}
Foi útil?

Solução

It seems that you have not added the required jar libraries to your project.

If you are on windows, try installing the JMF windows performance pack from this link:http://www.oracle.com/technetwork/java/javase/download-142937.html

  1. Install this exe file on your PC.
  2. Restart your computer.
  3. Open your project in netbeans.
  4. Right click on your project name in the project explorer window and open project properties.
  5. Go to the Libraries section. Under the Compile tab, select add jar/folder.
  6. Select and add all the jar files from the path where your JMF was installed. The default is C:\Program Files\JMF\lib. There should be 5 jar files.

This should resolve your error.

If you are on a different OS, follow the steps on the above mentioned link.

Outras dicas

If your on Mac you need to do this:

In OSX, you can set the classpath from scratch like this:

export CLASSPATH=/path/to/some.jar:/path/to/some/other.jar

Or you can add to the existing classpath like this:

export CLASSPATH=$CLASSPATH:/path/to/some.jar:/path/to/some/other.jar

This is answering your exact question, I'm not saying it's the right or wrong thing to do; I'll leave that for others to comment upon.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top