自定义标签 2023年4月24日12:17:09
parent
c3e9b30846
commit
9e8ebb3542
|
|
@ -0,0 +1,46 @@
|
|||
package com.zhangmeng.tools.builder;
|
||||
|
||||
import com.zhangmeng.tools.music.musicPlayer.MusicPlayer;
|
||||
import javafx.util.Builder;
|
||||
|
||||
/**
|
||||
* @author : 芊芊墨客
|
||||
* @version : 1.0
|
||||
* @date : 2023-04-24 11:18
|
||||
*/
|
||||
public class MusicPlayerBuilder implements Builder<MusicPlayer>{
|
||||
|
||||
private String file_path ;
|
||||
private String file_lyric ;
|
||||
private String singer;
|
||||
|
||||
|
||||
@Override
|
||||
public MusicPlayer build() {
|
||||
return new MusicPlayer(file_path,file_lyric,singer);
|
||||
}
|
||||
|
||||
public String getFile_path() {
|
||||
return file_path;
|
||||
}
|
||||
|
||||
public void setFile_path(String file_path) {
|
||||
this.file_path = file_path;
|
||||
}
|
||||
|
||||
public String getFile_lyric() {
|
||||
return file_lyric;
|
||||
}
|
||||
|
||||
public void setFile_lyric(String file_lyric) {
|
||||
this.file_lyric = file_lyric;
|
||||
}
|
||||
|
||||
public String getSinger() {
|
||||
return singer;
|
||||
}
|
||||
|
||||
public void setSinger(String singer) {
|
||||
this.singer = singer;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package com.zhangmeng.tools.builder;
|
||||
|
||||
import com.zhangmeng.tools.music.musicPlayer.MusicPlayer;
|
||||
import javafx.fxml.JavaFXBuilderFactory;
|
||||
import javafx.util.Builder;
|
||||
import javafx.util.BuilderFactory;
|
||||
|
||||
/**
|
||||
* @author : 芊芊墨客
|
||||
* @version : 1.0
|
||||
* @date : 2023-04-24 11:21
|
||||
*/
|
||||
public class MusicPlayerBuilderFactory implements BuilderFactory {
|
||||
|
||||
private final JavaFXBuilderFactory jff = new JavaFXBuilderFactory();
|
||||
|
||||
@Override
|
||||
public Builder<?> getBuilder(Class<?> type) {
|
||||
if (type == MusicPlayer.class){
|
||||
return new MusicPlayerBuilder();
|
||||
}else {
|
||||
return jff.getBuilder(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
package com.zhangmeng.tools.config;
|
||||
|
||||
import cn.hutool.core.io.resource.ClassPathResource;
|
||||
import cn.hutool.core.io.resource.Resource;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.media.Media;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author : 芊芊墨客
|
||||
* @version : 1.0
|
||||
* @date : 2023-04-24 12:01
|
||||
*/
|
||||
public class MusicFileConfig {
|
||||
|
||||
public static ObservableList<File> dirs = FXCollections.observableArrayList();
|
||||
public static ObservableList<Media> medias = FXCollections.observableArrayList();
|
||||
public static ObservableList<File> files = FXCollections.observableArrayList();
|
||||
|
||||
public static void init(){
|
||||
files = getMusicFiles();
|
||||
medias = getMusicMedias();
|
||||
}
|
||||
|
||||
public static String config_path() {
|
||||
Resource resource = new ClassPathResource("music.properties");
|
||||
InputStream inputStream = resource.getStream();
|
||||
Properties properties = new Properties();
|
||||
try {
|
||||
properties.load(inputStream);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return properties.getProperty("base.music.path");
|
||||
}
|
||||
|
||||
public static ObservableList<File> getDirsList() {
|
||||
String dir = config_path();
|
||||
File file = new File(dir);
|
||||
if (file.exists() && file.isDirectory()) {
|
||||
dirs.add(file);
|
||||
}
|
||||
return dirs;
|
||||
}
|
||||
|
||||
public static ObservableList<File> getMusicFiles() {
|
||||
if (files.size() == 0) {
|
||||
getDirsList().forEach((dir) -> {
|
||||
if (dir.exists()) {
|
||||
File[] mfiles = dir.listFiles(new FilenameFilter() {
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith("mp3");
|
||||
}
|
||||
});
|
||||
files.addAll(mfiles);
|
||||
}
|
||||
});
|
||||
return files;
|
||||
} else {
|
||||
return files;
|
||||
}
|
||||
}
|
||||
|
||||
public static ObservableList<Media> getMusicMedias() {
|
||||
if (medias.size() == 0) {
|
||||
getDirsList().forEach((dir) -> {
|
||||
if (dir.exists()) {
|
||||
File[] files = dir.listFiles(new FilenameFilter() {
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith("mp3");
|
||||
}
|
||||
});
|
||||
for (File file : files) {
|
||||
String uri = file.toURI().toASCIIString();
|
||||
Media media = new Media(uri);
|
||||
medias.add(media);
|
||||
}
|
||||
}
|
||||
});
|
||||
return medias;
|
||||
} else {
|
||||
return medias;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -30,6 +30,7 @@ import cn.hutool.core.io.resource.Resource;
|
|||
import com.leewyatt.rxcontrols.controls.RXLrcView;
|
||||
import com.leewyatt.rxcontrols.controls.RXMediaProgressBar;
|
||||
import com.leewyatt.rxcontrols.pojo.LrcDoc;
|
||||
import com.zhangmeng.tools.config.MusicFileConfig;
|
||||
import com.zhangmeng.tools.utils.*;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.property.SimpleDoubleProperty;
|
||||
|
|
@ -78,6 +79,8 @@ import java.util.Properties;
|
|||
import java.util.Random;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import static com.zhangmeng.tools.config.MusicFileConfig.*;
|
||||
|
||||
/**
|
||||
* @author : 芊芊墨客
|
||||
* @version : 1.0
|
||||
|
|
@ -86,9 +89,6 @@ import java.util.ResourceBundle;
|
|||
@Slf4j
|
||||
public class MusicController {
|
||||
|
||||
private static ObservableList<File> dirs = FXCollections.observableArrayList();
|
||||
private static ObservableList<Media> medias = FXCollections.observableArrayList();
|
||||
private static ObservableList<File> files = FXCollections.observableArrayList();
|
||||
public ScrollPane scrollPane;
|
||||
|
||||
public MediaPlayer getMp() {
|
||||
|
|
@ -192,10 +192,8 @@ public class MusicController {
|
|||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
files = getMusicFiles();
|
||||
initListView();
|
||||
medias = getMusicMedias();
|
||||
|
||||
initListView();
|
||||
medias.addListener(new ListChangeListener<Media>() {
|
||||
public void onChanged(Change<? extends Media> c) {
|
||||
while (c.next()) {
|
||||
|
|
@ -391,7 +389,7 @@ public class MusicController {
|
|||
MusicController.this.playindex.set((MusicController.this.playindex.get() + 1) % medias.size());
|
||||
}
|
||||
if (MusicController.this.cycletype.get() == 2) {
|
||||
MusicController.this.playindex.set(MusicController.this.ran.nextInt(MusicController.this.medias.size()));
|
||||
MusicController.this.playindex.set(MusicController.this.ran.nextInt(medias.size()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -511,7 +509,7 @@ public class MusicController {
|
|||
|
||||
public void myPlay() {
|
||||
this.mp.dispose();
|
||||
this.mp = new MediaPlayer(this.medias.get(this.playindex.get()));
|
||||
this.mp = new MediaPlayer(medias.get(this.playindex.get()));
|
||||
initProgressBar(mp);
|
||||
this.mp.setOnReady(() -> {
|
||||
MusicController.this.mp.play();
|
||||
|
|
@ -600,8 +598,8 @@ public class MusicController {
|
|||
MenuItem mi1 = new MenuItem("从列表中移除");
|
||||
mi1.setOnAction(new EventHandler<ActionEvent>() {
|
||||
public void handle(ActionEvent event) {
|
||||
MusicController.getMusicFiles().remove(cell.getIndex());
|
||||
MusicController.getMusicMedias().remove(cell.getIndex());
|
||||
getMusicFiles().remove(cell.getIndex());
|
||||
getMusicMedias().remove(cell.getIndex());
|
||||
}
|
||||
});
|
||||
ContextMenu cm = new ContextMenu(mi1);
|
||||
|
|
@ -684,66 +682,10 @@ public class MusicController {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static ObservableList<File> getDirsList() {
|
||||
String dir = config_path();
|
||||
File file = new File(dir);
|
||||
if (file.exists() && file.isDirectory()) {
|
||||
dirs.add(file);
|
||||
}
|
||||
return dirs;
|
||||
}
|
||||
|
||||
public static String config_path() {
|
||||
Resource resource = new ClassPathResource("music.properties");
|
||||
InputStream inputStream = resource.getStream();
|
||||
Properties properties = new Properties();
|
||||
try {
|
||||
properties.load(inputStream);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return properties.getProperty("base.music.path");
|
||||
}
|
||||
|
||||
public static ObservableList<Media> getMusicMedias() {
|
||||
if (medias.size() == 0) {
|
||||
getDirsList().forEach((dir) -> {
|
||||
if (dir.exists()) {
|
||||
File[] files = dir.listFiles(new FilenameFilter() {
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith("mp3");
|
||||
}
|
||||
});
|
||||
for (File file : files) {
|
||||
String uri = file.toURI().toASCIIString();
|
||||
Media media = new Media(uri);
|
||||
medias.add(media);
|
||||
}
|
||||
}
|
||||
});
|
||||
return medias;
|
||||
} else {
|
||||
return medias;
|
||||
}
|
||||
}
|
||||
|
||||
public static ObservableList<File> getMusicFiles() {
|
||||
if (files.size() == 0) {
|
||||
getDirsList().forEach((dir) -> {
|
||||
if (dir.exists()) {
|
||||
File[] mfiles = dir.listFiles(new FilenameFilter() {
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith("mp3");
|
||||
}
|
||||
});
|
||||
files.addAll(mfiles);
|
||||
}
|
||||
});
|
||||
return files;
|
||||
} else {
|
||||
return files;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void addDir(File file) {
|
||||
File[] addfiles = file.listFiles((dir, name) -> name.endsWith("mp3"));
|
||||
|
|
|
|||
|
|
@ -131,9 +131,7 @@ public class MusicDownloadController {
|
|||
tabPane.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Tab>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends Tab> observable, Tab oldValue, Tab newValue) {
|
||||
byte[] bytes = newValue.getText().getBytes(Charset.forName("GBk"));
|
||||
String text = new String(bytes, StandardCharsets.UTF_8);
|
||||
System.out.println(text);
|
||||
System.out.println(newValue.getText());
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
package com.zhangmeng.tools.music.musicPlayer;
|
||||
|
||||
/**
|
||||
* @author : 芊芊墨客
|
||||
* @version : 1.0
|
||||
* @date : 2023-04-24 11:15
|
||||
*/
|
||||
public class MusicPlayer {
|
||||
|
||||
private String file_path ;
|
||||
private String file_lyric ;
|
||||
private String singer;
|
||||
|
||||
public MusicPlayer() {
|
||||
}
|
||||
|
||||
public MusicPlayer(String file_path, String file_lyric, String singer) {
|
||||
this.file_path = file_path;
|
||||
this.file_lyric = file_lyric;
|
||||
this.singer = singer;
|
||||
}
|
||||
|
||||
public String getFile_path() {
|
||||
return file_path;
|
||||
}
|
||||
|
||||
public void setFile_path(String file_path) {
|
||||
this.file_path = file_path;
|
||||
}
|
||||
|
||||
public String getFile_lyric() {
|
||||
return file_lyric;
|
||||
}
|
||||
|
||||
public void setFile_lyric(String file_lyric) {
|
||||
this.file_lyric = file_lyric;
|
||||
}
|
||||
|
||||
public String getSinger() {
|
||||
return singer;
|
||||
}
|
||||
|
||||
public void setSinger(String singer) {
|
||||
this.singer = singer;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.zhangmeng.tools.views;
|
||||
|
||||
import com.zhangmeng.tools.config.MusicFileConfig;
|
||||
import com.zhangmeng.tools.utils.ImagePath;
|
||||
import com.zhangmeng.tools.utils.ResourcesUtils;
|
||||
import javafx.animation.*;
|
||||
|
|
@ -82,6 +83,11 @@ public class LoadView extends Application {
|
|||
showInfo("初始化目录...");
|
||||
}
|
||||
|
||||
if (newValue.doubleValue() == 0.2) {
|
||||
showInfo("初始化音乐目录...");
|
||||
MusicFileConfig.init();
|
||||
}
|
||||
|
||||
if (newValue.doubleValue() == 0.4) {
|
||||
showInfo("初始化系统配置...");
|
||||
}
|
||||
|
|
@ -110,23 +116,6 @@ public class LoadView extends Application {
|
|||
|
||||
@Override
|
||||
protected void updateValue(Double value) {
|
||||
|
||||
// try {
|
||||
// if (value == 0.1){
|
||||
// Thread.sleep(1500);
|
||||
// }
|
||||
//
|
||||
// if (value == 0.4){
|
||||
// Thread.sleep(1500);
|
||||
// }
|
||||
//
|
||||
// if (value == 0.9){
|
||||
// Thread.sleep(1500);
|
||||
// }
|
||||
// } catch (InterruptedException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
progressBar.setProgress(value);
|
||||
if (value >= 1) {
|
||||
service.cancel();
|
||||
|
|
|
|||
Loading…
Reference in New Issue