Moved callback interfaces.
This commit is contained in:
parent
0ba7ba8760
commit
75f310e140
@ -1,5 +1,6 @@
|
||||
package musicplayer;
|
||||
|
||||
import musicplayer.callbacks.LibraryCallbackInterface;
|
||||
import musicplayer.db.Gateway;
|
||||
import musicplayer.model.ExtractedMetadata;
|
||||
import org.jaudiotagger.audio.AudioFileIO;
|
||||
@ -12,25 +13,51 @@ import org.jaudiotagger.tag.TagException;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public final class LibraryUtils {
|
||||
|
||||
static final String musicFileExtensionRegex = ".*\\.(mp3|mp4|flac)";
|
||||
|
||||
public static void processSongsWithCallback(List<Path> rootDirectory, LibraryCallbackInterface callbackInterface){
|
||||
Thread thread = new Thread(() -> {
|
||||
try {
|
||||
processSongs(rootDirectory);
|
||||
callbackInterface.libraryUpdated(true);
|
||||
} catch (IOException e) {
|
||||
callbackInterface.libraryUpdated(false);
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public static void processSongsWithCallback(Path rootDirectory, LibraryCallbackInterface callbackInterface){
|
||||
Thread thread = new Thread(() -> {
|
||||
try {
|
||||
processSongs(rootDirectory);
|
||||
callbackInterface.libraryUpdated(true);
|
||||
} catch (IOException e) {
|
||||
callbackInterface.libraryUpdated(false);
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public static void processSongs(List<Path> rootDirectories) throws IOException {
|
||||
for(Path rootDirectory: rootDirectories)
|
||||
processSongs(rootDirectory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Walk through all files and directories recursively and index any music files with a correct extension
|
||||
*
|
||||
* @param rootDirectory Directory from which to start searching
|
||||
*/
|
||||
public static void processSongs(Path rootDirectory) {
|
||||
try {
|
||||
Files.walk(rootDirectory)
|
||||
.filter(f -> f.toString().matches(musicFileExtensionRegex))
|
||||
.map(LibraryUtils::autoParse).filter(Optional::isPresent).map(Optional::get).forEach(Gateway::addSong);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
public static void processSongs(Path rootDirectory) throws IOException {
|
||||
Files.walk(rootDirectory)
|
||||
.filter(f -> f.toString().matches(musicFileExtensionRegex))
|
||||
.map(LibraryUtils::autoParse).filter(Optional::isPresent).map(Optional::get).forEach(Gateway::addSong);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,6 @@
|
||||
package musicplayer;
|
||||
|
||||
import musicplayer.callbacks.PlayerCallbackInterface;
|
||||
import musicplayer.model.Song;
|
||||
import org.gstreamer.ElementFactory;
|
||||
import org.gstreamer.Gst;
|
||||
|
@ -1,5 +1,7 @@
|
||||
package musicplayer;
|
||||
|
||||
import musicplayer.callbacks.LibraryCallbackInterface;
|
||||
import musicplayer.callbacks.PlayerCallbackInterface;
|
||||
import musicplayer.db.DatabaseManager;
|
||||
import musicplayer.db.Gateway;
|
||||
import musicplayer.model.Album;
|
||||
@ -12,7 +14,7 @@ import javax.swing.tree.TreeNode;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
|
||||
public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterface{
|
||||
public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterface {
|
||||
private JTree libraryView;
|
||||
private JTable playList;
|
||||
private JPanel mainPanel;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package musicplayer;
|
||||
package musicplayer.callbacks;
|
||||
|
||||
public interface LibraryCallbackInterface {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package musicplayer;
|
||||
package musicplayer.callbacks;
|
||||
|
||||
import musicplayer.model.Song;
|
||||
|
Loading…
Reference in New Issue
Block a user