[英]Easy way to store MP3 file-path to variable and read from another class?
I'm trying to create a MP3 player program and I need a way to store the file-path of the mp3 in a variable so I can load the variable in another class and play that file. 我正在尝试创建MP3播放器程序,我需要一种将mp3的文件路径存储在变量中的方法,以便可以将变量加载到另一个类中并播放该文件。 Current code block for save/load is .txt now, but I need to replace it with the variable save. 现在,用于保存/加载的当前代码块是.txt,但是我需要将其替换为变量save。
try {
// What to do with the file.
textarea.read( new FileReader( file.getAbsolutePath() ), null );
} catch (IOException ex) {
System.out.println("Problem accessing file"+file.getAbsolutePath());
}
} else {
System.out.println("File access cancelled.");
}
I'm using these imports in the class reading the variable, 我在类中使用这些导入来读取变量,
import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
import java.net.*;
import java.io.*;
import java.io.FileInputStream;
import java.util.*;
import javazoom.jl.player.*;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.openal.Audio;
import org.newdawn.slick.openal.AudioLoader;
import org.newdawn.slick.openal.SoundStore;
import org.newdawn.slick.util.ResourceLoader;
As well as the import for the class in question. 以及有关课程的导入。
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
int returnVal = fileChooser.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
try{
FileInputStream mp3 = new FileInputStream(fileChooser.getSelectedFile());
Player playMP3 = new Player(mp3);
}catch(Exception e){System.out.println(e);
} }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.