Jump to content

Confused on playingSoundsStopTime


Mctittles

Recommended Posts

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

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