[英]JavaFX mediaplayer playing video in eclipse but not in runnable jar
我幾天來一直遇到這個問題,無法找到解決方案。 問題是當我在eclipse中運行程序時,我的介紹視頻會顯示並播放,但是當我將其導出到可運行的jar中時,視頻不會加載,只有jframe可以加載。
我正在使用帶有e(fx)clipse的eclipse。
在我的主類中,我只是創建一個Jframe並將MediaPanel對象添加到Jframe中:
mediaPanel = new MediaPanel( "/videos/Composite2.avi" );
frame.getContentPane().add(mediaPanel);
這是我的MediaPanel類別
import java.awt.BorderLayout;
import java.awt.Component;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.media.CannotRealizeException;
import javax.media.Manager;
import javax.media.NoPlayerException;
import javax.media.Player;
import javax.swing.JPanel;
public class MediaPanel extends JPanel
{
Player mediaPlayer;
public MediaPanel( String mediaURL ) throws MalformedURLException
{
URL mediaURL1 = this.getClass().getResource(mediaURL);
System.out.println(mediaURL1);
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
mediaPlayer = Manager.createRealizedPlayer( mediaURL1 );
// 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
catch ( CannotRealizeException cannotRealizeException )
{
System.err.println( "Could not realize media player" );
} // end catch
catch ( IOException iOException )
{
System.err.println( "Error reading from the source" );
} // end catch
} // end MediaPanel constructor
public void stop(){
mediaPlayer.stop();
}
} // end class MediaPanel
您是否已安裝這些庫。
狄拉克庫,1.0.2-9.fc18.i686.rpm
libavcodec52-0.7.15-32.fc18.i686.rpm
libavformat52-0.7.15-32.fc18.i686.rpm
libavutil50-0.7.15-32.fc18.i686.rpm
libxavs1-0.1.51-2.fc18.i686.rpm
安裝這些文件后,javafx會像音樂一樣播放音樂。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.