Fixed music player file from chain store
This commit is contained in:
parent
eec062010d
commit
9153e324e4
|
@ -83,9 +83,10 @@ public class TosAmpDeskApp extends AbstractDeskApp implements DeskAppRenderer {
|
|||
music.stop();
|
||||
}
|
||||
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("Play");
|
||||
ImGui.tableSetupColumn("List");
|
||||
ImGui.tableSetupColumn("Name");
|
||||
ImGui.tableHeadersRow();
|
||||
int i=1;
|
||||
|
@ -99,6 +100,8 @@ public class TosAmpDeskApp extends AbstractDeskApp implements DeskAppRenderer {
|
|||
music.play(song);
|
||||
}
|
||||
ImGui.tableNextColumn();
|
||||
ImGui.selectable(song.getPlaylist(), music.isPlaying(song), ImGuiSelectableFlags.None);
|
||||
ImGui.tableNextColumn();
|
||||
ImGui.selectable(song.getName(), music.isPlaying(song), ImGuiSelectableFlags.None);
|
||||
ImGui.popID();
|
||||
i++;
|
||||
|
|
|
@ -5,23 +5,88 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class M3UParser {
|
||||
|
||||
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<>();
|
||||
}
|
||||
|
||||
public class M3UTrack {
|
||||
private Map<String, String> images = new HashMap<>();
|
||||
|
||||
public M3UPlaylist() {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
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 M3UPlaylist parse(InputStream stream) throws IOException {
|
||||
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();
|
||||
M3UExtLine extLine = M3UExtLine.NONE;
|
||||
M3UTrack track = null;
|
||||
String imageType = null;
|
||||
|
||||
BufferedReader buffer = new BufferedReader(new InputStreamReader(stream));
|
||||
String line = buffer.readLine();
|
||||
|
@ -30,7 +95,45 @@ public class M3UParser {
|
|||
}
|
||||
|
||||
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;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package love.distributedrebirth.gdxapp4d.app.tosamp.music;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -12,6 +14,8 @@ import com.badlogic.gdx.audio.Music.OnCompletionListener;
|
|||
import com.badlogic.gdx.files.FileHandle;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -31,23 +35,25 @@ public class MusicManager {
|
|||
}
|
||||
|
||||
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) {
|
||||
|
||||
List<File> playlists = warpShip.searchMagic(context, "audio/mpegurl");
|
||||
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() {
|
||||
|
|
|
@ -11,10 +11,12 @@ import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
|
|||
public class MusicSong {
|
||||
private final FileHandle fileHandle;
|
||||
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.name = name;
|
||||
this.playlist = playlist;
|
||||
}
|
||||
|
||||
public FileHandle getFileHandle() {
|
||||
|
@ -24,4 +26,8 @@ public class MusicSong {
|
|||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getPlaylist() {
|
||||
return playlist;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue