Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (488)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Creating a new AudioClip from byte[]  (Read 745 times)
0 Members and 1 Guest are viewing this topic.
Offline eromemmaps

Junior Newbie




Java games rock!


« Posted 2005-04-23 15:02:23 »

Hi all!

I have a case where i load an .au file from a zip file. I have a wrapper class that i use for all sfx and which uses AudioClips. But it seems its only possible to load an Audioclip from an URL  Huh

I have access to the byte[] of the .au file and would like to stick using the AudioClip interface. Looking at the Applet.java implementation of getAudioclip got me nowhere, as it just forwards the call to AppletContext (which is defined per browser?)
Offline Mr_Light

Senior Member




shiny.


« Reply #1 - Posted 2005-04-24 00:33:14 »

try to have look at http://java.sun.com/j2se/1.4.2/docs/api/javax/sound/sampled/spi/AudioFileReader.html sicking it in an audioClip well... you can adleast play it.


-

url only is because applet security model and all its not expected to load stuff from many other places. Also what might be usefull to note is that some ppl might wonder why you are using zip's while there is jar (profided offcourse that this concerns an applet in the first place offcourse).

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #2 - Posted 2005-04-24 07:26:25 »

You could try something like this, where your sound is in byte array musicLoop.  16bit samples are stored as byte pairs (big-endian) so you need to split them up suitably when storing them.

1  
2  
3  
4  
5  
            AudioFormat audioFormat = new AudioFormat(16000f, 16, 1, true, true);
            DataLine.Info info = new DataLine.Info(Clip.class, audioFormat);
            clip = (Clip)AudioSystem.getLine(info);
            clip.open(audioFormat, musicLoop, 0, musicLoop.length);
            clip.loop(Clip.LOOP_CONTINUOUSLY);


I'm not sure whether using AudioSystem.getLine() is a good idea as I believe there is a bug in Java 1.5 to do with the mixer defaulting to a hardware mixer which doesn't work.  It may be necessary to enumerate all the mixers and explicitly choose the software mixer and then use that to do getLine().

If anyone has experience on this, please  comment on whether the mixer issue is an issue with the above code.

Time flies like a bird. Fruit flies like a banana.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (17 views)
2014-08-28 18:26:30

CopyableCougar4 (26 views)
2014-08-22 19:31:30

atombrot (39 views)
2014-08-19 09:29:53

Tekkerue (36 views)
2014-08-16 06:45:27

Tekkerue (33 views)
2014-08-16 06:22:17

Tekkerue (22 views)
2014-08-16 06:20:21

Tekkerue (33 views)
2014-08-16 06:12:11

Rayexar (69 views)
2014-08-11 02:49:23

BurntPizza (46 views)
2014-08-09 21:09:32

BurntPizza (37 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!