Jump to content

Mctittles

Members
  • Posts

    44
  • Joined

  • Last visited

Converted

  • Gender
    Undisclosed
  • Personal Text
    I am new!

Mctittles's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. So I figured it out. Here is how to get an input stream from an audio resource: resourceLocation = currentRecord.getRecordResource("records." + myNewRecord.recordName); SoundEventAccessorComposite sound = Minecraft.getMinecraft().getSoundHandler().getSound(resourceLocation); resourceLocationFile = sound.func_148720_g().getSoundPoolEntryLocation(); InputStream inputStream = Minecraft.getMinecraft().getResourceManager().getResource(resourceLocationFile).getInputStream(); Using JAudioTagger I was able to get the song length of an .ogg file. This isn't ideal for most projects because it requires a file location instead of an inputStream. Right now it works for me because all my files are in a resourcePack that everyone has a copy of but in the future I'd like to find a way using only the inputStream: resourceLocation = currentRecord.getRecordResource("records." + myNewRecord.recordName); try { SoundEventAccessorComposite sound = Minecraft.getMinecraft().getSoundHandler().getSound(resourceLocation); resourceLocationFile = sound.func_148720_g().getSoundPoolEntryLocation(); File soundFile = new File("resourcepacks/moreMusic/assets/minecraft/" + resourceLocationFile.getResourcePath()); AudioFile f = AudioFileIO.read(soundFile); AudioHeader audioHeader = f.getAudioHeader(); currentLength=audioHeader.getTrackLength(); PacketHandler.INSTANCE.sendToServer(new ClientSendsServerGetsSongTimes(slotSent, counter, currentLength, this)); } catch (Exception ignored) { ignored.printStackTrace(); }
  2. I may have found a way digging deep in the minecraft sound files to get the length from an input stream. But as per my original post I can't seem to get an input stream returned from a resource.
  3. Thanks! I'm looking into ogg libraries now. Would be good if I could just use the minecraft soundsystem to get the song length but I don't see any way to do that. The files I'm working with will always be in a resource pack (mod is designed to allow you to add music), but either way I don't see how to convert an InputStream into an audio input stream. Any suggestions?
  4. I tried a direct file just to see if the rest of the code would work: try { File file = new File("C:/Users/Mctittles/AppData/Roaming/.minecraft/resourcepacks/moreMusic/assets/minecraft/sounds/01 - Intro-.ogg"); AudioInputStream audioInputStream= AudioSystem.getAudioInputStream(file); AudioFormat format = audioInputStream.getFormat(); long frames = audioInputStream.getFrameLength(); double durationInSeconds = (frames+0.0) / format.getFrameRate(); moreMusic.logger.info("Length in seconds: "+durationInSeconds); } catch (Exception ignored) { moreMusic.logger.info("couldn't get the resource for song length: "+ignored); } Unfortunately I get this error: javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input file So I guess I need two things now. Getting the file from a resource AND getting the length of an ogg file. Bummer...
  5. It appears I need to get the file name to put in resourceLocation. The music items for my mod are added via a config and linked to a resourcepack .json file. Anyone know how to get the file name so I can path to it?
  6. Made a new post as this topic title was no longer relevant: http://www.minecraftforge.net/forum/index.php/topic,25374.0.html
  7. I'd like to get the length of a music file. This is how I currently get the resource for my item: ResourceLocation resourceLocation = currentRecord.getRecordResource("records." + currentRecord.recordName); However that doesn't work in the following: try { AudioInputStream audioInputStream = (AudioInputStream)Minecraft.getMinecraft().getResourceManager().getResource(resourceLocation).getInputStream(); AudioFormat format = audioInputStream.getFormat(); long frames = audioInputStream.getFrameLength(); double durationInSeconds = (frames+0.0) / format.getFrameRate(); moreMusic.logger.info("Length in seconds: "+durationInSeconds); } catch (Exception ignored) { moreMusic.logger.info("couldn't get the resource for song length: "+ignored); } I get the error: java.io.FileNotFoundException: minecraft:records.record2 Does anyone know the correct way to do this? I do not know the name of the song file because in this mod users add them with resource packs.
  8. Well, I've got part of it figured out for getting the song length: try { AudioInputStream audioInputStream = (AudioInputStream)Minecraft.getMinecraft().getResourceManager().getResource(resourceLocation).getInputStream(); AudioFormat format = audioInputStream.getFormat(); long frames = audioInputStream.getFrameLength(); double durationInSeconds = (frames+0.0) / format.getFrameRate(); } Only problem is I don't know what to put in for resourceLocation. Using this does not work: ResourceLocation resourceLocation = currentRecord.getRecordResource(currentRecord.recordName); java.io.FileNotFoundException: minecraft:record2 The sound locations are set in a .json file so maybe that's part of the problem. That and I really don't understand how Minecraft resources work .
  9. Yes and that's expected. This mod also allows you to add as much music as you like through a config + resource pack and everyone on the server has the same one. So looking into getting path to file from Resource then how to get sound length of .ogg.
  10. I'm modifying code for a multi disc jukebox that is currently using the clients to determine when a song is done and then all clients tell all other clients to play the next track, but that method causes a number of problems like: When someone mutes their volume all tracks skip for everyone. If there is lag involved or a connection hiccup the user with the lag causes tracks to skip. Sometimes messages get doubled and it tries to play a track twice. etc... So logically it would be better if the server was the only one who told people when to change tracks. Only one message and missing files, volume, etc wouldn't interfere with it. Of course since the server doesn't use the soundsystem and actually have the files I was going to use System.currentTimeMillis() to keep track of play time and send the length of the songs to the server whenever the container is changed. Currently I have it successfully changing tracks every 10 seconds and it works great, but the only piece of the puzzle left is to get the length of the song.
  11. Good idea, I'll give it a try. I actually changed my code to stop with an identifier cause I couldn't get this to work, but I'll get back to it in a bit as I would prefer not to have to keep track of the previous sound manually.
  12. Ahh yes I see. Thanks! Looking through paul's sound system class I can't find anything to get the length either. Looks like I'm going to have to see how to do it in Java against the .ogg directly.
  13. I'm trying to get the length of a music sound so I can send it to the server and the server can determine when the sound is done playing. I was looking into getting playingSoundsStopTime from the SoundManger class, however looking through the code I find this is how it's set: this.playingSoundsStopTime.put(s, Integer.valueOf(this.playTime + 20)); So it just adds 20 ticks to it? That doesn't seem correct, otherwise music would always stop playing after 20 ticks...
  14. Hello. So what am I doing wrong here? Map<ChunkCoordinates, ISound> mapSoundPositions = ReflectionHelper.getPrivateValue(RenderGlobal.class, Minecraft.getMinecraft().renderGlobal, "field_147593_P", "mapSoundPositions"); ISound sound =mapSoundPositions.get(new ChunkCoordinates(xCoord, yCoord, zCoord)); if (sound != null) { HashBiMap<String, ISound> playingSounds = ReflectionHelper.getPrivateValue(SoundManager.class, SoundManagerInstances.soundManagerInstance, "playingSounds", "field_148629_h"); String soundString= playingSounds.inverse().get(sound); SoundManagerInstances.soundSystemInstance.stop(soundString); } There is definitely a sound at the coordinates but the "sound" is always null.
  15. Oh, looks like you can also pass an array of field names so it works in both environments (I think). I'm learning!
×
×
  • Create New...

Important Information

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