获取使用javafx播放的mp3文件 [英] Getting a mp3 file to play using javafx

查看:386
本文介绍了获取使用javafx播放的mp3文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经花了几个小时,查看如何在日食中获得某种形式的音频,并且每一步都遇到麻烦。目前我有一些应该工作的东西,但是我收到一个错误:

I have spent hours today looking up how to get some form of audio in eclipse and have had trouble every step of the way. Currently I have something that should work but I get an error:

线程main中的异常java.lang.IllegalArgumentException:预期的文件名作为参数
com.sun.javafx.css.parser.Css2Bin.main(Css2Bin.java:44)

Exception in thread "main" java.lang.IllegalArgumentException: expected file name as argument at com.sun.javafx.css.parser.Css2Bin.main(Css2Bin.java:44)

我已经从有人工作的人基本上复制了这个。我想说,FX库是添加在哪里应该的。我知道这不是幻想,但我只是在尝试基础。

I have basically copied this from someone who had it working. I would like to say that the FX lib is added where it should be. I know this isn't fancy but I was just trying the basics.

package b;
import java.io.File;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
public class test {

    public static void main(String[] args){
    String uriString = new File("C:\\Users\\Mike\\workspace\\b\\src\\hero.mp3").toURI().toString()
    MediaPlayer player = new MediaPlayer( new Media(uriString));
    player.play();
}}

我还尝试了许多不同的路径名,以防不正确幸运的是,我也试图复制并粘贴我在eclipse中获得的路径名,转到属性例如:/b/src/hero.mp3。帮助不胜感激,让我脱离这个噩梦。

I have also tried many different path names in case it was wrong with no luck, I also just tried to copy and paste the path name that i got in eclipse by going to properties ex: /b/src/hero.mp3. Help would be appreciated to get me out of this nightmare.

推荐答案

位于工作区外部的文件应包含在 file:// 前缀。演示功能的简单示例是

The files located outside the workspace should be included with file:// prefix. A simple example demonstrating the functionality is

public class Reproductor extends Application {

    public static void main(String[] args) {
        launch(args); 
    }

   @Override
   public void start(Stage stage) throws Exception {
       Media media = new Media("file:///Movies/test.mp3"); //replace /Movies/test.mp3 with your file
       MediaPlayer player = new MediaPlayer(media); 
       player.play();
   }  
 }

这篇关于获取使用javafx播放的mp3文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆