使用另一个类的JavaFX mediaplayer播放音频文件
媒体播放器类是好的。但是,我不能播放另一个类中存储的mp3文件(当鼠标单击时)。有人能查一下我的密码吗使用另一个类的JavaFX mediaplayer播放音频文件,java,swing,media-player,javafx,netbeans-7,Java,Swing,Media Player,Javafx,Netbeans 7,媒体播放器类是好的。但是,我不能播放另一个类中存储的mp3文件(当鼠标单击时)。有人能查一下我的密码吗 package mediaplayer; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.media.Media; import javafx.stage.Stag
package mediaplayer;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.media.Media;
import javafx.stage.Stage;
public class MediaPlayer extends Application {
private static final String MEDIA_URL = "http://download.oracle.com/otndocs/products/javafx/oow2010-2.flv";
private static String arg1;
@Override public void start(Stage stage) {
stage.setTitle("Media Player");
Group root = new Group();
Scene scene = new Scene(root,600,265);
// create media player
Media media = new Media((arg1 != null) ? arg1 : MEDIA_URL);
javafx.scene.media.MediaPlayer mediaPlayer = new javafx.scene.media.MediaPlayer(media);
mediaPlayer.setAutoPlay(true);
MediaControl mediaControl = new MediaControl(mediaPlayer);
scene.setRoot(mediaControl);
scene.getStylesheets().add(MediaPlayer.class.getResource("mediaplayer.css").toExternalForm());
// show stage
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
if (args.length > 0) {
arg1 = args[0];
}
Application.launch(args);
}
}
这是我试图用来播放音频文件的类:
package mediaplayer;
import java.awt.Cursor;
/**
*
* @author Yves
*/
public class LacherPrise extends javax.swing.JFrame {
/**
* Creates new form LacherPrise
*/
public LacherPrise() {
this.setVisible(true);
// définition de la taille de la fenêtre de l’éditeur
setBounds(200, 100, 800, 600);
initComponents();
}
当我运行程序(在下面点击的鼠标上)时,会出现以下两个错误:
错误1:线程“AWT-EventQueue-0”java.lang.UnsupportedOperationException:尚未实现中的异常
错误No 2:线程“thread-3”java.lang.IllegalStateException:工具箱未初始化
我需要关于如何实现异常的帮助
private void audio010MouseClicked(java.awt.event.MouseEvent evt) {
//getting URL to a sound file stored locally
String MEDIA_URL = "file:///C:/Users/Yves/Documents/NetBeansProjects/ExamenFinSessionJavaFX/src/RessourcesLacherPrise/Aff010.mp3";
Media media = new Media(MEDIA_URL.toString());
MediaPlayer MediaPlayer = new MediaPlayer();
MediaPlayer.play(MEDIA_URL);
}
我认为主要的问题是JavaFX工具包尚未初始化。请看以下问题: 只要在代码的开头写上这一点就可以解决问题:
newjfxpanel()代码>当您尝试播放mp3时会发生什么?当我运行该程序(在下面单击的鼠标上)时,会出现以下两个错误:错误1:线程“AWT-EventQueue-0”java.lang中的异常。不支持操作异常:尚未实现错误2:线程“thread-3”中的异常IllegalStateException:Toolkit未初始化我需要关于如何实现异常的帮助。