Fixed music player file from chain store

This commit is contained in:
Willem Cazander 2022-03-13 01:15:51 +01:00
parent eec062010d
commit 9153e324e4
4 changed files with 138 additions and 20 deletions

View file

@ -83,9 +83,10 @@ public class TosAmpDeskApp extends AbstractDeskApp implements DeskAppRenderer {
music.stop(); music.stop();
} }
int flags = ImGuiTableFlags.ScrollX | ImGuiTableFlags.RowBg | ImGuiTableFlags.BordersOuter | ImGuiTableFlags.BordersV; int flags = ImGuiTableFlags.ScrollX | ImGuiTableFlags.RowBg | ImGuiTableFlags.BordersOuter | ImGuiTableFlags.BordersV;
ImGui.beginTable("playlist", 3, flags); ImGui.beginTable("playlist", 4, flags);
ImGui.tableSetupColumn("#", ImGuiTableColumnFlags.NoHide); ImGui.tableSetupColumn("#", ImGuiTableColumnFlags.NoHide);
ImGui.tableSetupColumn("Play"); ImGui.tableSetupColumn("Play");
ImGui.tableSetupColumn("List");
ImGui.tableSetupColumn("Name"); ImGui.tableSetupColumn("Name");
ImGui.tableHeadersRow(); ImGui.tableHeadersRow();
int i=1; int i=1;
@ -99,6 +100,8 @@ public class TosAmpDeskApp extends AbstractDeskApp implements DeskAppRenderer {
music.play(song); music.play(song);
} }
ImGui.tableNextColumn(); ImGui.tableNextColumn();
ImGui.selectable(song.getPlaylist(), music.isPlaying(song), ImGuiSelectableFlags.None);
ImGui.tableNextColumn();
ImGui.selectable(song.getName(), music.isPlaying(song), ImGuiSelectableFlags.None); ImGui.selectable(song.getName(), music.isPlaying(song), ImGuiSelectableFlags.None);
ImGui.popID(); ImGui.popID();
i++; i++;

View file

@ -5,23 +5,88 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
public class M3UParser { public class M3UParser {
private static final String M3U_HEADER = "#EXTM3U"; private static final String M3U_HEADER = "#EXTM3U";
private static final String M3U_EXTINF = "#EXTINF:";
private static final String M3U_PLAYLIST = "#PLAYLIST:";
private static final String M3U_EXTALB = "#EXTALB:";
private static final String M3U_EXTART = "#EXTART:";
private static final String M3U_EXTGENRE = "#EXTGENRE:";
private static final String M3U_EXTIMG = "#EXTIMG:";
public class M3UPlaylist { public static class M3UPlaylist {
private String name;
private String albumTitle;
private String albumArtist;
private String albumGenre;
private List<M3UTrack> tracks = new ArrayList<>(); private List<M3UTrack> tracks = new ArrayList<>();
private Map<String, String> images = new HashMap<>();
public M3UPlaylist() {
} }
public class M3UTrack { public String getName() {
return name;
} }
public M3UPlaylist parse(InputStream stream) throws IOException { public String getAlbumTitle() {
return albumTitle;
}
public String getAlbumArtist() {
return albumArtist;
}
public String getAlbumGenre() {
return albumGenre;
}
public List<M3UTrack> getTracks() {
return tracks;
}
public Map<String, String> getImages() {
return images;
}
}
public static class M3UTrack {
private int time;
private String name;
private String file;
public M3UTrack() {
}
public int getTime() {
return time;
}
public String getName() {
return name;
}
public String getFile() {
return file;
}
}
enum M3UExtLine {
NONE,
EXTINF,
EXTIMG,
}
public static M3UPlaylist parse(InputStream stream) throws IOException {
M3UPlaylist result = new M3UPlaylist(); M3UPlaylist result = new M3UPlaylist();
M3UExtLine extLine = M3UExtLine.NONE;
M3UTrack track = null;
String imageType = null;
BufferedReader buffer = new BufferedReader(new InputStreamReader(stream)); BufferedReader buffer = new BufferedReader(new InputStreamReader(stream));
String line = buffer.readLine(); String line = buffer.readLine();
@ -30,7 +95,45 @@ public class M3UParser {
} }
while ((line = buffer.readLine()) != null) { while ((line = buffer.readLine()) != null) {
if (line.isEmpty()) {
continue;
}
if (extLine == M3UExtLine.EXTINF) {
extLine = M3UExtLine.NONE;
track.file = line;
result.tracks.add(track);
continue;
}
if (extLine == M3UExtLine.EXTIMG) {
extLine = M3UExtLine.NONE;
result.images.put(imageType, line);
continue;
}
int arguIndex = line.indexOf(":");
if (arguIndex == -1) {
continue;
}
String lineArgu = line.substring(arguIndex + 1);
if (line.startsWith(M3U_PLAYLIST)) {
result.name = lineArgu;
} else if (line.startsWith(M3U_EXTALB)) {
result.albumTitle = lineArgu;
} else if (line.startsWith(M3U_EXTART)) {
result.albumArtist = lineArgu;
} else if (line.startsWith(M3U_EXTGENRE)) {
result.albumGenre = lineArgu;
} else if (line.startsWith(M3U_EXTIMG)) {
imageType = lineArgu;
extLine = M3UExtLine.EXTIMG;
} else if (line.startsWith(M3U_EXTINF)) {
track = new M3UTrack();
extLine = M3UExtLine.EXTINF;
int commaIndex = lineArgu.indexOf(",");
String timeStr = lineArgu.substring(0, commaIndex);
String trackName = lineArgu.substring(commaIndex + 1);
track.time = Integer.parseInt(timeStr);
track.name = trackName;
}
} }
return result; return result;

View file

@ -1,6 +1,8 @@
package love.distributedrebirth.gdxapp4d.app.tosamp.music; package love.distributedrebirth.gdxapp4d.app.tosamp.music;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -12,6 +14,8 @@ import com.badlogic.gdx.audio.Music.OnCompletionListener;
import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.files.FileHandle;
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
import love.distributedrebirth.gdxapp4d.app.tosamp.music.M3UParser.M3UPlaylist;
import love.distributedrebirth.gdxapp4d.app.tosamp.music.M3UParser.M3UTrack;
import love.distributedrebirth.gdxapp4d.tos4.service.SystemWarpShip; import love.distributedrebirth.gdxapp4d.tos4.service.SystemWarpShip;
/** /**
@ -31,23 +35,25 @@ public class MusicManager {
} }
public void addBackgroundMusic(FileHandle file) { public void addBackgroundMusic(FileHandle file) {
musicSongs.add(new MusicSong(file, file.name())); musicSongs.add(new MusicSong(file, file.name(), ""));
} }
public void init(BundleContext context, SystemWarpShip warpShip) { public void init(BundleContext context, SystemWarpShip warpShip) {
List<File> playlists = warpShip.searchMagic(context, "audio/mpegurl"); List<File> playlists = warpShip.searchMagic(context, "audio/mpegurl");
for (File playlist:playlists) { for (File playlist:playlists) {
System.out.println("Playlist: "+playlist); try {
M3UPlaylist play = M3UParser.parse(new FileInputStream(playlist));
for (M3UTrack track:play.getTracks()) {
FileHandle fileHandle = Gdx.files.absolute(playlist.getParent() + "/" + track.getFile());
musicSongs.add(new MusicSong(fileHandle, track.getName(), play.getName()));
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} }
/*
addBackgroundMusic(Gdx.files.internal("music/sanctumwave-risen.mp3"));
addBackgroundMusic(Gdx.files.internal("music/sanctumwave-devine-intellect.mp3"));
addBackgroundMusic(Gdx.files.internal("music/theselfhelpgroup-temple-os.mp3"));
addBackgroundMusic(Gdx.files.internal("music/sanctumwave-nightwalk.mp3"));
addBackgroundMusic(Gdx.files.internal("music/beeble-i-used-temple-os-to-write.mp3"));
addBackgroundMusic(Gdx.files.internal("music/ryanfarran-risen-temple-os.mp3"));
*/
} }
public void dispose() { public void dispose() {

View file

@ -11,10 +11,12 @@ import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
public class MusicSong { public class MusicSong {
private final FileHandle fileHandle; private final FileHandle fileHandle;
private final String name; private final String name;
private final String playlist;
public MusicSong(FileHandle fileHandle, String name) { public MusicSong(FileHandle fileHandle, String name, String playlist) {
this.fileHandle = fileHandle; this.fileHandle = fileHandle;
this.name = name; this.name = name;
this.playlist = playlist;
} }
public FileHandle getFileHandle() { public FileHandle getFileHandle() {
@ -24,4 +26,8 @@ public class MusicSong {
public String getName() { public String getName() {
return name; return name;
} }
public String getPlaylist() {
return playlist;
}
} }