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