Jump to content

kwikmatt

Members
  • Posts

    2
  • Joined

  • Last visited

Everything posted by kwikmatt

  1. Ok, so I have successfully created a Java class that saves the latest user's Spotify Session's album to a file named album_art.png. Here is where I am at so far: public class SpoticraftArtDownloader { public static String imageURL = null; private static void downloadImage() throws Exception { if (imageURL == null) return; URL url = new URL(imageURL); InputStream in = new BufferedInputStream(url.openStream()); OutputStream out = new BufferedOutputStream(new FileOutputStream("./album_art.png")); for ( int i; (i = in.read()) != -1; ) { out.write(i); } in.close(); out.close(); } private static void deleteImage() { File file = new File("./album_art.png"); if (file.exists()) file.delete(); } public static void rotateImage(String url) throws Exception { deleteImage(); imageURL = url; downloadImage(); } } However, this is saving the image into the run directory, which from my understanding is inaccessible from the mod, with something like ResourceLocation nowPlayingArt = new ResourceLocation(SpoticraftMod.MODID, "textures/album_art.png"); RenderSystem.setShaderTexture(0, nowPlayingArt); How can I point SpoticraftArtDownloader to download the images into the textures folder?
  2. I am trying to create a HUD "Now Playing" element that displays the current song, artist, album, and corresponding album art live based on what the user is listening to using the Spotify API. Sort of like a widget, for now, that appears on the top left corner of the user's screen. Here's a visual representation of where I am currently (see top left). In that square-like space to the left of the song details, I want to squeeze in the Album Art. I have an object that holds the image URL of the currently playing album, so I figured I would attempt something like this: private static String nowPlayingAlbum = spoticraftInstance.nowPlaying.item.album.images.get(1).url; private static ResourceLocation COVER_ART = new ResourceLocation(SpoticraftMod.MODID, nowPlayingAlbum == null ? "" : nowPlayingAlbum); FYI, spoticraftInstance is a direct Gson mapping of the JSON response from Spotify's Get Currently Playing Track API. This updates every second on a separate thread so spoticraftInstance always contains the latest song information. However upon launching the game it crashes with the following message: Caused by: net.minecraft.ResourceLocationException: Non [a-z0-9/._-] character in path of location: spoticraft:https://i.scdn.co/image/ab67616d00001e028dc0d801766a5aa6a33cbe37 This was a surprise, so I am trying to think of how to get around this properly. Should I download the image first, display it, then delete it after that song is no longer playing? Or is there a better way I am unaware of that will allow me to draw the image live as the URL changes? Here is the entire declaration of my HUD element for reference as of now: import static com.example.spoticraft.SpoticraftCommon.literalOrEllipse; import static com.example.spoticraft.SpoticraftMod.spoticraftInstance; public class SpoticraftDrawing { private static String nowPlayingAlbum = spoticraftInstance.nowPlaying.item.album.images.get(1).url; private static ResourceLocation COVER_ART = new ResourceLocation(SpoticraftMod.MODID, nowPlayingAlbum == null ? "" : nowPlayingAlbum); private static final ResourceLocation BACKGROUND = new ResourceLocation(SpoticraftMod.MODID, "textures/background.png"); public static final IGuiOverlay SPOTIFCRAFT_OVERLAY = ((gui, poseStack, partialTick, width, height) -> { int x = 5; int y = 5; int backgroundWidth = 200; int backgroundHeight = 50; RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderColor(1f, 1f, 1f, 1f); RenderSystem.setShaderTexture(0, BACKGROUND); NowPlaying currentSong = spoticraftInstance.nowPlaying; Font font = gui.getFont(); GuiComponent.blit(poseStack, x, y, 0, 0, backgroundWidth, backgroundHeight, 0, 0); int textX = 50; if (currentSong != null) { RenderSystem.setShaderTexture(0, COVER_ART); GuiComponent.blit(poseStack, x + 5, 5, 0, 0, 50, 50, 0, 0); GuiComponent.drawString(poseStack, font, literalOrEllipse("§f§l" + currentSong.item.name), textX, 12, 0); GuiComponent.drawString(poseStack, font, literalOrEllipse("§e" + currentSong.item.artists.get(0).name), textX, 25, 0); GuiComponent.drawString(poseStack, font, literalOrEllipse("§6§o" + currentSong.item.album.name), textX, 38, 0); } else { if (SpoticraftMod.spoticraftInstance.getRefreshToken() == null) { GuiComponent.drawString(poseStack, font, "§f/spoticraft init to see your music", 20, 12, 0); } else { GuiComponent.drawString(poseStack, font, "§6§oNothing Playing", 20, 12, 0); } } }); } Thank you!
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.