Retrieving Sounds from a Jar file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • BlackHawke

    Retrieving Sounds from a Jar file

    Hello!

    In our game package (www.andromedaonline.net) we are having problems with
    sounds. We have placed them in a jar file, and are trying to access them
    from there.

    The jar file has a directory structure. A number of sounds have the same
    name, but are in a different directory (for example, our game has 5 races.
    Each race has the same set of sounds- button clicks, etc, but the actual
    sound is different).

    We've attempted doing this (for buttonClickSoun d, made when a player hits a
    button):

    soundJar = new JarResources("A ndromedaSFX.jar ");
    URL clickSoundURL = new
    URL(soundJar.ge tResource("/com/Andromeda/sounds/main/Main-click.wav"));
    buttonClickSoun d = Applet.newAudio Clip(clickSound URL);

    However soundJar.getRes ource returns BYTE and we need STRING in the above
    example. we replaced "clickSound URL" with:

    URL clickSoundURL = PreGamePanel.cl ass.getResource ("Main-click.wav");

    but that returns a null pointer exception (presumably because I don't have
    the directory structure... Nor do I know how it's supposed to know which jar
    file to get the file from in the second example).

    Nobody here has any experience with accessing .wav files from a jar file. We
    would greatly appreciate any help one could offer.

    Thank you for your time.

    Nick Soutter



  • Ryan Stewart

    #2
    Re: Retrieving Sounds from a Jar file

    "BlackHawke " <blackhawke@leg acygames.net> wrote in message
    news:jtXTb.1216 4$uM2.6775@news read1.news.pas. earthlink.net.. .[color=blue]
    > Hello!
    >
    > In our game package (www.andromedaonline.net) we are having problems with
    > sounds. We have placed them in a jar file, and are trying to access them
    > from there.
    >
    > The jar file has a directory structure. A number of sounds have the same
    > name, but are in a different directory (for example, our game has 5 races.
    > Each race has the same set of sounds- button clicks, etc, but the actual
    > sound is different).
    >
    > We've attempted doing this (for buttonClickSoun d, made when a player hits[/color]
    a[color=blue]
    > button):
    >
    > soundJar = new JarResources("A ndromedaSFX.jar ");
    > URL clickSoundURL = new
    > URL(soundJar.ge tResource("/com/Andromeda/sounds/main/Main-click.wav"));
    > buttonClickSoun d = Applet.newAudio Clip(clickSound URL);
    >
    > However soundJar.getRes ource returns BYTE and we need STRING in the above
    > example. we replaced "clickSound URL" with:
    >
    > URL clickSoundURL = PreGamePanel.cl ass.getResource ("Main-click.wav");
    >
    > but that returns a null pointer exception (presumably because I don't have
    > the directory structure... Nor do I know how it's supposed to know which[/color]
    jar[color=blue]
    > file to get the file from in the second example).
    >
    > Nobody here has any experience with accessing .wav files from a jar file.[/color]
    We[color=blue]
    > would greatly appreciate any help one could offer.
    >
    > Thank you for your time.
    >
    > Nick Soutter[/color]

    Did you google this before posting? Seems to me I researched this same thing
    not long ago and found some good suggestions in the archives. Search for
    "getImageFromJa r". I think that's what I found. It should be easily
    adaptable to any file type.


    Comment

    • BlackHawke

      #3
      Re: Retrieving Sounds from a Jar file

      We have checked Google, AltaVista, and Java.sun.com

      We successfully get many graphics files from our jar file.

      The problem is that because the Applet.newAudio Clip method requires a
      url/string, the same method to obtain graphics from a jar file can not be
      used here. The graphics methods (which use "getResourc e"- included in my
      sample) can not return strings.

      Thanks for the thought, though. :(

      Nick Soutter





      "Ryan Stewart" <zzanNOtozz@gSP AMo.com> wrote in message
      news:cMGdnRCvUp-V0L3dRVn-jQ@texas.net...[color=blue]
      > "BlackHawke " <blackhawke@leg acygames.net> wrote in message
      > news:jtXTb.1216 4$uM2.6775@news read1.news.pas. earthlink.net.. .[color=green]
      > > Hello!
      > >
      > > In our game package (www.andromedaonline.net) we are having problems[/color][/color]
      with[color=blue][color=green]
      > > sounds. We have placed them in a jar file, and are trying to access them
      > > from there.
      > >
      > > The jar file has a directory structure. A number of sounds have the same
      > > name, but are in a different directory (for example, our game has 5[/color][/color]
      races.[color=blue][color=green]
      > > Each race has the same set of sounds- button clicks, etc, but the actual
      > > sound is different).
      > >
      > > We've attempted doing this (for buttonClickSoun d, made when a player[/color][/color]
      hits[color=blue]
      > a[color=green]
      > > button):
      > >
      > > soundJar = new JarResources("A ndromedaSFX.jar ");
      > > URL clickSoundURL = new
      > > URL(soundJar.ge tResource("/com/Andromeda/sounds/main/Main-click.wav"));
      > > buttonClickSoun d = (clickSoundURL) ;
      > >
      > > However soundJar.getRes ource returns BYTE and we need STRING in the[/color][/color]
      above[color=blue][color=green]
      > > example. we replaced "clickSound URL" with:
      > >
      > > URL clickSoundURL = PreGamePanel.cl ass.getResource ("Main-click.wav");
      > >
      > > but that returns a null pointer exception (presumably because I don't[/color][/color]
      have[color=blue][color=green]
      > > the directory structure... Nor do I know how it's supposed to know which[/color]
      > jar[color=green]
      > > file to get the file from in the second example).
      > >
      > > Nobody here has any experience with accessing .wav files from a jar[/color][/color]
      file.[color=blue]
      > We[color=green]
      > > would greatly appreciate any help one could offer.
      > >
      > > Thank you for your time.
      > >
      > > Nick Soutter[/color]
      >
      > Did you google this before posting? Seems to me I researched this same[/color]
      thing[color=blue]
      > not long ago and found some good suggestions in the archives. Search for
      > "getImageFromJa r". I think that's what I found. It should be easily
      > adaptable to any file type.
      >
      >[/color]


      Comment

      • chris

        #4
        Re: Retrieving Sounds from a Jar file

        BlackHawke wrote:
        [color=blue]
        > Hello!
        >
        > In our game package (www.andromedaonline.net) we are having problems with
        > sounds. We have placed them in a jar file, and are trying to access them
        > from there.
        >
        > The jar file has a directory structure. A number of sounds have the same
        > name, but are in a different directory (for example, our game has 5 races.
        > Each race has the same set of sounds- button clicks, etc, but the actual
        > sound is different).[/color]

        I think you're looking for the jar URL hack. It looks like this:
        jar:http://www.xxx.yyy/jarfile.jar!/mypackage/myclass.class
        That's a URL meaning "fetch http://www.xxx.yyy/jarfile.jar and look inside
        for a file called /mypackage/myclass.class". Of course the inner URL could
        just as well be a local file.

        This thing is so ugly I prefer not to talk about it too much. Enjoy.

        --
        Chris Gray chris@kiffer.eu net.be
        /k/ Embedded Java Solutions

        Comment

        • Raymond DeCampo

          #5
          Re: Retrieving Sounds from a Jar file

          BlackHawke wrote:[color=blue]
          > Hello!
          >
          > In our game package (www.andromedaonline.net) we are having problems with
          > sounds. We have placed them in a jar file, and are trying to access them
          > from there.
          >
          > The jar file has a directory structure. A number of sounds have the same
          > name, but are in a different directory (for example, our game has 5 races.
          > Each race has the same set of sounds- button clicks, etc, but the actual
          > sound is different).
          >
          > We've attempted doing this (for buttonClickSoun d, made when a player hits a
          > button):
          >
          > soundJar = new JarResources("A ndromedaSFX.jar ");
          > URL clickSoundURL = new
          > URL(soundJar.ge tResource("/com/Andromeda/sounds/main/Main-click.wav"));
          > buttonClickSoun d = Applet.newAudio Clip(clickSound URL);
          >
          > However soundJar.getRes ource returns BYTE and we need STRING in the above
          > example. we replaced "clickSound URL" with:
          >
          > URL clickSoundURL = PreGamePanel.cl ass.getResource ("Main-click.wav");
          >
          > but that returns a null pointer exception (presumably because I don't have
          > the directory structure... Nor do I know how it's supposed to know which jar
          > file to get the file from in the second example).
          >
          > Nobody here has any experience with accessing .wav files from a jar file. We
          > would greatly appreciate any help one could offer.
          >
          > Thank you for your time.
          >
          > Nick Soutter
          >
          >
          >[/color]

          I think you've made this too complicated. Why not put the jar
          containing the files in the classpath? Then use:

          URL url = this.getClassLo ader().getResou rce("/path/to/sound/file.au");

          Ray


          Comment

          • BlackHawke

            #6
            Re: Retrieving Sounds from a Jar file

            That did it, Thanks!!!


            "chris" <chris@kiffer.e unet.be> wrote in message
            news:c00t13$7e6 $1@reader08.wxs .nl...[color=blue]
            > BlackHawke wrote:
            >[color=green]
            > > Hello!
            > >
            > > In our game package (www.andromedaonline.net) we are having problems[/color][/color]
            with[color=blue][color=green]
            > > sounds. We have placed them in a jar file, and are trying to access them
            > > from there.
            > >
            > > The jar file has a directory structure. A number of sounds have the same
            > > name, but are in a different directory (for example, our game has 5[/color][/color]
            races.[color=blue][color=green]
            > > Each race has the same set of sounds- button clicks, etc, but the actual
            > > sound is different).[/color]
            >
            > I think you're looking for the jar URL hack. It looks like this:
            > jar:http://www.xxx.yyy/jarfile.jar!/mypackage/myclass.class
            > That's a URL meaning "fetch http://www.xxx.yyy/jarfile.jar and look inside
            > for a file called /mypackage/myclass.class". Of course the inner URL could
            > just as well be a local file.
            >
            > This thing is so ugly I prefer not to talk about it too much. Enjoy.
            >
            > --
            > Chris Gray chris@kiffer.eu net.be
            > /k/ Embedded Java Solutions
            >[/color]


            Comment

            • BlackHawke

              #7
              Re: Retrieving Sounds from a Jar file

              It is in the classpath. :(

              This has been tried, didn't work.

              Nick
              "Raymond DeCampo" <rdecampo@spa m-I-am-not.twcny.rr.co m> wrote in message
              news:_kbVb.4831 0$%72.21171@twi ster.nyroc.rr.c om...[color=blue]
              > BlackHawke wrote:[color=green]
              > > Hello!
              > >
              > > In our game package (www.andromedaonline.net) we are having problems[/color][/color]
              with[color=blue][color=green]
              > > sounds. We have placed them in a jar file, and are trying to access them
              > > from there.
              > >
              > > The jar file has a directory structure. A number of sounds have the same
              > > name, but are in a different directory (for example, our game has 5[/color][/color]
              races.[color=blue][color=green]
              > > Each race has the same set of sounds- button clicks, etc, but the actual
              > > sound is different).
              > >
              > > We've attempted doing this (for buttonClickSoun d, made when a player[/color][/color]
              hits a[color=blue][color=green]
              > > button):
              > >
              > > soundJar = new JarResources("A ndromedaSFX.jar ");
              > > URL clickSoundURL = new
              > > URL(soundJar.ge tResource("/com/Andromeda/sounds/main/Main-click.wav"));
              > > buttonClickSoun d = Applet.newAudio Clip(clickSound URL);
              > >
              > > However soundJar.getRes ource returns BYTE and we need STRING in the[/color][/color]
              above[color=blue][color=green]
              > > example. we replaced "clickSound URL" with:
              > >
              > > URL clickSoundURL = PreGamePanel.cl ass.getResource ("Main-click.wav");
              > >
              > > but that returns a null pointer exception (presumably because I don't[/color][/color]
              have[color=blue][color=green]
              > > the directory structure... Nor do I know how it's supposed to know which[/color][/color]
              jar[color=blue][color=green]
              > > file to get the file from in the second example).
              > >
              > > Nobody here has any experience with accessing .wav files from a jar[/color][/color]
              file. We[color=blue][color=green]
              > > would greatly appreciate any help one could offer.
              > >
              > > Thank you for your time.
              > >
              > > Nick Soutter
              > >
              > >
              > >[/color]
              >
              > I think you've made this too complicated. Why not put the jar
              > containing the files in the classpath? Then use:
              >
              > URL url = this.getClassLo ader().getResou rce("/path/to/sound/file.au");
              >
              > Ray
              >
              >[/color]


              Comment

              Working...