Sound im my file

Hi, here the code:
import java.awt.*;
import java.io.FileInputStream;
import java.applet.*;
import sun.audio.*;
import hsa.Console;
import java.awt.*;
import java.io.FileInputStream;
import java.applet.*;
import sun.audio.*;
import hsa.Console;
import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.applet.*;
public class PlayMusic
static JTextArea Musicarea;
JFrame frame3;
// Create an array for five pieces of music
static AudioData[] audioData = new AudioData [5];
static AudioDataStream[] audioStream = new AudioDataStream [5];
static ContinuousAudioDataStream[] continuousAudioDataStream =
new ContinuousAudioDataStream [5];
public void Music ()
frame3 = new JFrame ("Box");
frame3.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
addComponentsToPane3 (frame3.getContentPane ());
frame3.pack ();
frame3.setSize (330, 300);
frame3.setLocationRelativeTo (null);
frame3.setVisible (true);
public void addComponentsToPane3 (Container pane3)
pane3.setLayout (null);
Musicarea = new JTextArea ();
Musicarea.setEditable (false);
Musicarea.setBounds (0, 0, 330, 210);
pane3.add (Musicarea);
public static void main (String[] args)
char c;
int choice, newChoice;
int ch = 0;
// JFrame c = new JFrame
/* c.println ("This program will randomly play one of five pieces " +
"music. It will start a");
c.println ("different piece of music each time you press a key. " +
"Press 'q' to quit"); */
//c.print ("\nLoading music... ");
loadMusic ("music0.au", 0);
loadMusic ("music1.au", 1);
loadMusic ("music2.au", 2);
loadMusic ("music3.au", 3);
loadMusic ("music4.au", 4);
// c.println ("Done.");
choice = (int) (Math.random () * 5);
// Musicarea.setText ("\nPlaying song #" + choice);
while (true)
Musicarea.setText ("\nPlaying song #" + choice);
loop (choice);
//ch = c.getChar ();
if (ch == 'q')
break;
do
newChoice = (int) (Math.random () * 5);
while (choice == newChoice);
stop (choice);
choice = newChoice;
} // main method
static void loadMusic (String fileName, int index)
try
FileInputStream fis = new FileInputStream (fileName);
AudioStream tempAudioStream = new AudioStream (fis);
audioData [index] = tempAudioStream.getData ();
audioStream [index] = null;
continuousAudioDataStream [index] = null;
catch (Exception e)
System.out.println ("Unable to load " + fileName + ": " + e);
System.exit (0);
} // loadMusic method
static void loop (int index)
continuousAudioDataStream [index] =
new ContinuousAudioDataStream (audioData [index]);
AudioPlayer.player.start (continuousAudioDataStream [index]);
} // loop (void)
static void play (int index)
audioStream [index] = new AudioDataStream (audioData [index]);
AudioPlayer.player.start (audioStream [index]);
} // play (void)
static void stop (int index)
if (audioStream [index] != null)
AudioPlayer.player.stop (audioStream [index]);
if (continuousAudioDataStream [index] != null)
AudioPlayer.player.stop (continuousAudioDataStream [index]);
} // stop ()
} // PlayMusic classI have made some mistakes that i dont know how to fix, what i want is for the five tracks to play in random order in a JFrame, can someone please take a look and see if you can help?
thanks alot
Message was edited by:
GraDoN

Hi,
I tried your code and i successfully play 4 files randomly and continuously but only problem is that it showing one exception that
Exception in thread "main" java.lang.IllegalThreadStateException
     at java.lang.Thread.start(Thread.java:571)
     at PlayMusic.main(PlayMusic.java:83)
becoz of one method that i used extra. if i remove that one it doesn't play.
I am giving the working ocde here. If any one find the reason for that exception thn plz let me know.
*************code start from here *******************
import java.awt.*;
import java.io.FileInputStream;
import java.applet.*;
import sun.audio.*;
//import hsa.Console;
import java.awt.*;
import java.io.FileInputStream;
import java.applet.*;
import sun.audio.*;
//import hsa.Console;
import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.applet.*;
public class PlayMusic
     static JTextArea Musicarea;
     JFrame frame3;
     // Create an array for five pieces of music
     static AudioData[] audioData = new AudioData [4];
     static AudioDataStream[] audioStream = new AudioDataStream [4];
     static ContinuousAudioDataStream[] continuousAudioDataStream =new ContinuousAudioDataStream [4];
     public void Music ()
          frame3 = new JFrame ("Box");
          frame3.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
          addComponentsToPane3 (frame3.getContentPane ());
          frame3.pack ();
          frame3.setSize (330, 300);
          frame3.setLocationRelativeTo (null);
          frame3.setVisible (true);
     public void addComponentsToPane3 (Container pane3)
          pane3.setLayout (null);
          Musicarea = new JTextArea ();
          Musicarea.setEditable (false);
          Musicarea.setBounds (0, 0, 330, 210);
          pane3.add (Musicarea);
     public static void main (String[] args)
          char c;
          int choice, newChoice;
          int ch = 0;
          loadMusic ("/home/araghuvanshi/Desktop/my_clonefone_files/media_0.wav", 0);
          loadMusic ("/home/araghuvanshi/Desktop/my_clonefone_files/media_1.wav", 1);
          loadMusic ("/home/araghuvanshi/Desktop/my_clonefone_files/media_2.wav", 2);
          loadMusic ("/home/araghuvanshi/Desktop/my_clonefone_files/media_3.wav", 3);
          choice = (int) (Math.random () * 4);
          String t=""+choice;
          //Musicarea.setText ("\nPlaying song #" + choice);
          int i=0;
          while (i<4)
               i++;
               System.out.println(choice);
               //Musicarea.setText ("\nPlaying song #" + choice);
               //System.out.println(t);
               //Musicarea.setText(t);
               loop (choice);
               //ch = c.getChar ();
               if (ch == 'q')
               break;
               do
                    newChoice = (int) (Math.random () * 4);
               while (choice == newChoice);
               AudioPlayer.player.start();
               stop (choice);
               choice = newChoice;
     } // main method
     static void loadMusic (String fileName, int index)
          try
               FileInputStream fis = new FileInputStream (fileName);
               AudioStream tempAudioStream = new AudioStream (fis);
               audioData [index] = tempAudioStream.getData ();
               audioStream [index] = null;
               continuousAudioDataStream [index] = null;
          catch (Exception e)
               System.out.println ("Unable to load " + fileName + ": " + e);
               System.exit (0);
     } // loadMusic method
     static void loop (int index)
          System.out.println("Index====="+index);
          continuousAudioDataStream [index] =     new ContinuousAudioDataStream (audioData [index]);
          AudioPlayer.player.start (continuousAudioDataStream [index]);
     } // loop (void)
     static void play (int index)
          audioStream [index] = new AudioDataStream (audioData [index]);
          AudioPlayer.player.start (audioStream [index]);
     } // play (void)
     static void stop (int index)
          if (audioStream [index] != null)
          AudioPlayer.player.stop (audioStream [index]);
          if (continuousAudioDataStream [index] != null)
          AudioPlayer.player.stop (continuousAudioDataStream [index]);
     } // stop ()
} // PlayMusic class
All the Best.
Regards,
Anil R

Similar Messages

  • STRANGE problem with sound in SWF files...Please help if you know how...

    Hello,
         Okay, so, I recently learned how to use Adobe InDesign to create a book.  there is a lot a still don't know.  When I export my document as a SWF file, it works great and has sound and animations where it should.  However, if I move that SWF to a new location, such as my desktop or uploading it to an e-mail, it looses all the sound information.  To add sound to each page, I added a hidden object to each page that was the sound file so that I could attach it to a button.  It seems that it is loosing that sound file if I move it to a new location.  Any ideas or solutions?

    UPDATE:  I have learned that my problem is related to a "resourse folder" which must go wherever the file goes in order for it to have sound.  This is a bit inconvinient for me, as my client is computer illiterate.  I really want to find a way to just embed the sound into a file that you can just open and play.  To the best of my knowlege, SWF format is the only format that allows for the page turning animation.  Does anyone know a way to embed the sound into the SWF file or am I SOL here?

  • I have elements 12 in Windows 7 but is unable to see mp4 files in the organiser. The sound from the file is there but no image!

    I have elements 12 in Windows 7 but is unable to see mp4 (Canon G16) files in the organiser. The sound from the file is there but no image!
    Other file formats from Canon is no problen. So What to do??
    Roger

    Me again,
    A friend suggested that I do a system restore.
    I did a search for system restore in Windows 7 and got a very intuitive menu.
    I selected an earlier system restore point and executed the restore.
    After the computer restart I reloaded Firefox 5.0 and the Ask.com problem was corrected.
    My friend says this approach may work about 25% of the time to fix this kind of problem. In my case it worked and I am happy.
    Thanks all.
    Richard Ryer

  • Problem accessing sounds in jar file

    Hi,
    I have made a program and packed it to a jar file.
    Everything works fine in the IDE, so this is purely a matter of jar access.
    The jar has 6 folders.
    framework (which is one of my packages)
    META-INF
    sound (also my package)
    sounds (my wav files for the program)
    sprite (another package)
    sprites (my graphics for the program).
    I access the graphics in sprites, from a class in sprite and have no problem with it.
    try {               
                   URL url = this.getClass().getClassLoader().getResource(ref);               
                   if (url == null) {
                        fail("Kan ikke finde ref: "+ref);
                   sourceImage = ImageIO.read(url);
              } catch (IOException e) {
                   fail("fejl ved load: "+ref);
              }The problem is accessing the wav file in the sounds folder from a class in the sound folder.
    try{
                   AudioInputStream stream = AudioSystem.getAudioInputStream(new File("Sounds/1999.wav"));
                   AudioFormat format = stream.getFormat();
                   DataLine.Info info = new DataLine.Info(Clip.class, stream.getFormat(),
                             ((int)stream.getFrameLength()*format.getFrameSize()));
                   clip = (Clip) AudioSystem.getLine(info);
                   clip.open(stream);
              }I have tried to use the class loader like this (instead of AudioSystem.getAudioInputStream) :
    AudioInputStream stream = (AudioInputStream) this.getClass().getClassLoader().getResourceAsStream("sounds/1999.wav");          
    but it didnt help.
    Does anyone have any suggestione?
    Please, if all you can do, is paste a link to the java API, save your energy. I have already looked and it was no help, as im still only a student of java.
    I would like an actual suggestion, so i can see it work, then i can make work my way through the API from there.
    Edited by: Mondariz on May 7, 2008 8:26 AM

    Don't try to use a File object to access resources from the jar. You have a working process for accessing the sprites, just use the same process to access the sounds. Only not quite the same method, there's one method which returns a URL and a very similar method which returns an InputStream. I would post the link to the documentation but you asked for us to not do that. Anyway you seem to know where it is.

  • No sound in swf file

    I need to resize an flv file. I opened it in Flash and embedded it as a movie clip in the timeline. I also embedded into the timeline frame sequence. I was able to resize the file successfully. When I preview publish it as a swf file, it plays with sound in Flash. When I export the clip to a flv file, it doesn't play with sound. I have also tried to convert the flash from swf back to flv using After Effects, but there is no sound either in AE and when I play the converted file in Adobe Media Player. I am stumped on how to get any sounds from this file and appreciate any help I could get.

    Have you asked Maps Marker Pro for support for their product?
    https://www.mapsmarker.com/support/
    Chances are you need specific code for Gecko based browsers, which might need different code than Trident, WebKit, and Blink based browsers use.

  • Scratchy, distorted, garbled sound from MP3s files

    I'm having really horrible scratchy, distorted, garbled sound from MP3 files. AAC encoded files play extremely clearly on iTunes 10.5

    After reviewing all comments, it appears that this issue is squarely with the 10.5 upgrade that Apple did on I tunes. I have done all the uninstall and re-install that you can do.  Songs play fine on some, terrible on others, but yet they all will play on Windows Media Player. I can't believe it is the chipset for those that AMD processors, because everything was fine on the 10.4.  So,  Apple please fix this or offer us a way to uninstall from the 10.5 to the 10.4 where everything should be okay.   Awaiting your reply with thousands of others!

  • Newbie question: Why is "learn sound model" greyed out when trying to remove background sounds in a file using the Spectral Frequency display?

    I am trying to remove background sounds in a file using the Spectral Frequency display. The first edit on a new file, this process works fine:
    1. use brush to cover sound
    2. right click, learn sound model
    3. effects/noise-reduction-restoration/Sound Remover
    The next time I try to remove another sound in the file, "learn sound model" is greyed out. I have to close the file and reopen to be able to make another edit. What on earth is going on? Can it only learn one sound model or something?
    I'm a newbie, so thanks in advance for your advice!

    My daughter has had her Razr for about 9 months now.  About two weeks ago she picked up her phone in the morning on her way to school when she noticed two cracks, both starting at the camera lens. One goes completely to the bottom and the other goes sharply to the side. She has never dropped it and me and my husband went over it with a fine tooth comb. We looked under a magnifying glass and could no find any reason for the glass to crack. Not one ding, scratch or bang. Our daughter really takes good care of her stuff, but we still wanted to make sure before we sent it in for repairs. Well we did and we got a reply from Motorola with a picture of the cracks saying this was customer abuse and that it is not covered under warranty. Even though they did not find any physical damage to back it up. Well I e-mailed them back and told them I did a little research and found pages of people having the same problems. Well I did not hear from them until I received a notice from Fed Ex that they were sending the phone back. NOT FIXED!!! I went to look up why and guess what there is no case open any more for the phone. It has been wiped clean. I put in the RMA # it comes back not found, I put in the ID #, the SN# and all comes back not found. Yet a day earlier all the info was there. I know there is a lot more people like me and all of you, but they just don't want to be bothered so they pay to have it fix, just to have it do it again. Unless they have found the problem and only fixing it on a customer pay only set up. I am furious and will not be recommending this phone to anyone. And to think I was considering this phone for my next up grade! NOT!!!!

  • I have completed a song on the GarageBand app which plays fine. I export it via email and it opens up in iTunes on my PC fine but when you play it there is no sound from the file. Anyone know I am doing wrong please?

    I have completed a song on the GarageBand app which plays fine. I export it via email and it opens up in iTunes on my PC fine but when you play it there is no sound from the file. Anyone know I am doing wrong please?

    you might need codecs on you pc. i find vlc player and codecs is perfect for music and videos.

  • No sound in .mov file in premiere elements 8

    hi, i'm running premiere elements 8 in windows xp.  i have several clips i wanted to edit that were given to me by a friend.  they are in .mov file format.  when i play them using quicktime they play perfectly, sound video everything.  when i import them into elements though the video plays fine, but there is no sound.  i even tried to edit one and then save it to my drive, but there was no sound in the file.  what is the solution?  thanks in advance for help.

    .MOV files are not edited natively in PE and will present a number of issues, all or most of them will equate to heartache and depression.
    Review this thread for a fix to smooth editing of .mov files using PE:
    http://forums.adobe.com/message/2367563

  • No sound on mpeg files

    I can't get my quicktime pro to play the sound from mpeg files

    We need more information to help you.
    Have these MPEG files been "exported"?
    Do you get any sound from .mov files? Do Web files (trailers) work?

  • HT204382 Hi, Ive just got myself a Macbook Pro, and Im having problems with sound on movie files. The format is wmv and they play OK on a windows 7 laptop, and Im trying to play them now on the MAC. The picture is OK , but no sound. I have Flip4Mac - no d

    Hi, Ive just got myself a Macbook Pro, and Im having problems with sound on movie files. The format is wmv and they play OK on a windows 7 laptop, and Im trying to play them now on the MAC. The picture is OK , but no sound. I have Flip4Mac - no diference

    Download and install the free VLC for Mac - that should work:
    http://www.videolan.org/vlc/download-macosx.html

  • How to deal with scratchy sound in AVI file from BetaCam masters

    Recently, I got out some BetaCam edit masters of videos I produced in the 1990s. The university instructional technology center transfered the masters to Mini-DV tape, then made AVI files from the Mini-DV tapes. The AVI files sound fine when I play them from my hard drive, but when I use the AVI files in Premiere Pro CS4 and 1.5, the sound is scratchy--sort of like a scratchy record. So then I got the Mini-DV tape and decided to import the program, playing it on my Canon GL1 camcorder and capturing it in PP CS4. But the sound is even worse. Please advise. These programs are too important to not be able to convert them to YouTube and DVD formats.

    If things work OK in "programA" but not in "programB" (B being Premiere) that is usually a codec issue
    AVI is simply a wrapper... what is the codec?
    The first question at the end of this link has a link to the free GSPOT to find the codec
    First, work through all of the steps here http://ppro.wikia.com/wiki/Troubleshooting
    If your problem isn't fixed after you follow all of the steps, report back with the DETAILS asked for in the questions at the end of that link

  • No Sound playing AVI files in Quicktime Pro - help!

    Help! I just bought QT Pro for Windows(Xp) to convert my AVI files to Mpeg4 for my Ipod. The Apple Store sales guy promised it could be done. I see video but no sound on all of the AVI files. For example, on 2 of my AVI video files, according to Gspot, the video codecs are "divx 3 low motion" and "Xvid" and they are installed on my pc. According to Gspot, the audio codec required is "0x0055(MP3) ID'd as MPEG-1 Layer 3" which can play on
    --> {Fraunhofer IIS MPEG Layer-3 Codec (advanced)}
    --> {MPEG Layer-3 Decoder}
    which are both installed on my pc, yet I have no sound. I am stuck! The bit rate is 128. Should I be using another audio codec??? Where can I get it? Help! Anyone?

    Some of the avi files created on PCs use variable bit rate mp3 souind. QT will not play that type of mp3 in avi files.
    One way to deal with the issue is to convert the mp3 to a QT-friendly format. You can try this process, using this freeware Windows program: VirtualDub
    Open the problem file in VirtualDub. Set the Video mode to Direct Stream Copy. That will copy the video to the new file with no change. Set the Audio to Full Processor Mode. Then set the compression to IMA compression. Now use Save As Avi in the File menu to make a new file with a new name. Since only the audio is being changed it is a fairly rapid process.
    One last thing. To do this you do have to have the Windows codecs for those video formats installed. That is, you have to be able to play them in Windows Media Player. QT uses completely different codecs.

  • No sound for AVI files with Quicktime

    I know this is a well discussed topic, but I can't seem to fix this problem.
    I upgraded to Quicktime 7.5 and quickly found that I cannot get audio/sound out of my AVI files (most are short clips taken with my Casio Exlim Digital Camera). I tried installing Perian, but that didn't work. I tried reinstalling QT, and that didn't work. I tried repairing disk permissions and that didn't work. Finally, I thought perhaps I had a bad AppleIntermediateCodec file. I downloaded version 1.0.1 from Apple, but it won't let me load it - acts like its an update to an existing file, but the file is not on my system. Here is the contents of my Library/Componets folder:
    A52Codec.component
    AC3MovieImport.component
    AppleIntermediateCodec.component
    AudioCodecs.component
    file.temp
    Flip4Mac WMV Advanced.component
    Flip4Mac WMV Export.component
    Flip4Mac WMV Import.component
    Perian.component
    QuickTimeUSBVDCDigitizer.component
    Here is the contents of my Library/Quicktime folder:
    A52Codec.component
    AC3MovieImport.component
    AppleIntermediateCodec.component
    AudioCodecs.component
    file.temp
    Flip4Mac WMV Advanced.component
    Flip4Mac WMV Export.component
    Flip4Mac WMV Import.component
    Perian.component
    QuickTimeUSBVDCDigitizer.component
    I am the admin on the system, but I have two other accounts for my sons. Can anyone out there give me a clue as to what I should do next? Thanks.
    DadioCruton

    I am having the same problem. But it's even weirder. Any .avi file I created using my Flip Ultra camera will play with sound. One or two .avi movies I've d/l'd from the 'net will also play with sound. The remainder will not play with sound on QT (7.5). I have VLC, Real and DivX Player loaded, and all .avi files play on those players with sound, no problem.
    Now, my Library/Components folder is empty. My Library/QuickTime folder has the following:
    3ivxVideoCodec.component
    AC3MovieImport.component
    AC3MovieImport.component
    CanonMJPEGAVI.component
    CanonText.component
    Flip4Mac WMV Advanced.component
    Flip4Mac WMV Export.component
    Flip4Mac WMV Import.component
    XVid_Codec 1.0 alpha.component
    ZyGoAudioS.component
    ZyGoMJ2K.component
    ZyGoTimeCode.component
    I followed the instructions on this page, but it still isn't working:
    http://installingcats.com/2007/11/30/play-avi-divx-codec-movies-on-quicktime-in- mac-os-x-leopard/
    ZyGoVideo.component
    ZyGoVideo.component.hqx

  • Sound glitch? file -LOST S2E1 "Man of Science, Man of Faith"

    regarding the "Man of Science, Man of Faith" episode, (season 2 episode 1) the movie file purchased through the iTunes Music/Video store...
    at around 9:48 into the episode, does one else hear that sound glitch? it's pretty much obvious. just wondering if it's just a problem with my file...
    perhaps i need to download it again, maybe?
    thanks everyone.
    jp

    A few people have reported this problem, and we are still tracking it down.
    Meanbwhile, a new feature of iTunes 6.0 is resumable downloads. So you can cancel the download and retry later and iTunes will pick up where it left off. Try quitting iTunes which will stop the download, restarting your computer, and then do Check For Purchases in the Advanced menu in iTunes.

  • Playing sound over network file

    Hello,
             I have swf file in my domain which has to play sound file that is located over the network. say my domain is http://mydomain.com/play.aspx which hosts the swf file. This swf file plays a sound thats is located at \\SERVERNAME\PATH\xyz.mp3. This SERVERNAME can be local or network. When I try to access the sound file I get IO error 2032. I copied crossdomain.xml (with full access to *) under \\SERVERNAME server at the root path that is C:\ and also to \\SERVERNAME\PATH. It didnt work. IS there something that I m missing?..
    Thanks,
    Bharani

    it depends on the place you called this method and the place of the sound clip, the class within which you called the method must be at the same directory of the sound clip, if you used the file name as the parameter of this method without supplying directores like sounds/myClip.mid
    ex.
    package myPack.test
    class Test{
          getclass.getResource("myClip.mid"); //this call assumes that the file path is ...myPack/test/myClip.mid
    }GoodLuck

Maybe you are looking for

  • How to change the resolution of a page in iWeb

    Hi, I'm making a website for a project, and I decided to do it in iWeb. The brief of mt project says the resolution has to be 1024*768, however, when I change the resolution to this, the page instantly looks horrible with a white border to the right

  • FindClass() Problem Pls Help.. (URGENT!!)

    Hi, I trying to use the files from the book "JNI Programmer's Guide & Specifications" - Ch. 7., to create JVM & call a java method from c routine. I m working on Solaris machine. JVM is 1.1, so the correct part of the version independent code runs (r

  • MPLS load balancing

    Hello, Graph of the network is in the attachment. I have problem that loadbalanicing among two GigabitEtehernet links in OSPF (between PE4 and P1 router on the picture)doesn't work. Black link goes to 1G/s and begins to drop packets and red one stays

  • Linux acroread 8.1.2 can't change print command

    It won't let me do it and it won't let root do it. I use cups and don't use lpr

  • Show HREF content in a portlet

    If i use HREF, the content is opened in a new page. But my requirement is to open html/pdf files in a portlet. The way i know is to read the file either using util_file or dbms_lob.read utilities. Since i may have to read huge files, is there any oth