Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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 1506 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 implementation of getAudioclip got me nowhere, as it just forwards the call to AppletContext (which is defined per browser?)
Offline Mr_Light

Senior Devvie

Medals: 1


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

try to have look at 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.

            AudioFormat audioFormat = new AudioFormat(16000f, 16, 1, true, true);
            DataLine.Info info = new DataLine.Info(Clip.class, audioFormat);
            clip = (Clip)AudioSystem.getLine(info);
  , musicLoop, 0, musicLoop.length);

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  

EgonOlsen (74 views)
2018-06-10 19:43:48

EgonOlsen (55 views)
2018-06-10 19:43:44

EgonOlsen (75 views)
2018-06-10 19:43:20

DesertCoockie (255 views)
2018-05-13 18:23:11

nelsongames (154 views)
2018-04-24 18:15:36

nelsongames (154 views)
2018-04-24 18:14:32

ivj94 (895 views)
2018-03-24 14:47:39

ivj94 (156 views)
2018-03-24 14:46:31

ivj94 (808 views)
2018-03-24 14:43:53

Solater (172 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!