Solved Is there a way to get sound duration

Discussion in 'Plugin Development' started by Bilna, Sep 20, 2021.

  1. Offline

    Bilna

    Hi,

    I've done search for a hour and I found no solution. I want to get duration of an ogg sound that we assume it exists. I began making plugin yesterday so i'm not aware of what is possible and what's not.

    The sound is a custom one located in a resource pack. I want to get sound duration to put the value in a RepeatingTask and so looping sound x times. Obviously, any other solution that would make it would be gratefuly appreciated.
    Thanks :)
     
  2. Offline

    davidclue

  3. Offline

    Bilna

    Thanks for the reply, I saw this solution but it's kinda problematic since it needs the path leading to the ogg file, no ?
    Bukkit can playsound just with the name of the file, so it is able to find it, maybe we could atleast get the path with a method from a certain class ?
     
  4. Offline

    davidclue

    @Bilna Resource packs are stored in the .minecraft folder
     
  5. Offline

    Bilna

    I don't know how to locate .minecraft in client side files as I can't set an absolute path and I don't know how relative path are working since the plugin is only located in plugin server's folder
    Thanks
     
  6. Online

    timtower Administrator Administrator Moderator

    @Bilna Resource packs can change the length, how do you want to deal with that?
     
  7. Offline

    Bilna

    This is exactly what i'm struggling to do, for example, I got custom sounds in my resource pack. To make it works, i'm trying to set music's length as period for my repeating task.
    I thought there was a way to get length of a sound since vanilla playsound command can access to the song itself, and this, no matters if it's a custom one or not.
    Maybe another way to perform the same task would be to check if a player is (still) listening to the song but it would imply to check it every x second.
     
    Last edited: Sep 22, 2021
  8. Offline

    davidclue

    @Bilna

    Code:
    File resourcePack = new File("C:/Users/" + System.getProperty("user.name") + "/AppData/Roaming/.minecraft/resourcepacks/" + resourcePackName);
     
  9. Offline

    Bilna

    Thanks you !!
     

Share This Page