gpt4 book ai didi

JavaFX 媒体播放器在 Eclipse 中播放视频,但不在可运行的 jar 中播放

转载 作者:太空宇宙 更新时间:2023-11-04 14:53:40 24 4
gpt4 key购买 nike

这个问题我已经困扰好几天了,但找不到解决方案。问题是,当我在 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

最佳答案

您安装这些库了吗?

dirac-libs-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 就会像魅力一样播放音乐。

关于JavaFX 媒体播放器在 Eclipse 中播放视频,但不在可运行的 jar 中播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23475026/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com