Page 2 of 2 FirstFirst 12
Results 21 to 35 of 35
Like Tree1Likes

Thread: Mp3 in background?

  1. #21
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    (Reply #17) I get Using audio file /Users/seegee1237/NetBeansProjects/Celcius/300ViolinOrchestra.mp3
    I have no experience with sun.audio.* - see #14 for how I would play sound - but anyone who does is probably going to want a problem description. Does that file exist (a file with exactly that name)? Are there runtime errors (IOException)? What actually happens at runtime (sound, no sound etc)?

  2. #22
    seegee is offline Member
    Join Date
    Jul 2011
    Posts
    36
    Rep Power
    0

    Default

    Quote Originally Posted by pbrockway2 View Post
    I have no experience with sun.audio.* - see #14 for how I would play sound - but anyone who does is probably going to want a problem description. Does that file exist (a file with exactly that name)? Are there runtime errors (IOException)? What actually happens at runtime (sound, no sound etc)?
    Ok, while using your code, this is what happens. Yes, that file exists, I copied and pasted the exact name. At runtime, I do get an IO exception that says this: java.io.IOException: could not create audio stream from input stream
    at sun.audio.AudioStream.<init>(AudioStream.java:65)
    at CJSMoneyMachine.main(CJSMoneyMachine.java:126)

    Line 126 is: audioStream = new AudioStream(new FileInputStream("300ViolinOrchestra.mp3"));

    Other than the music part, the whole rest of the program works fine. There is just no sound in the speakers.

  3. #23
    seegee is offline Member
    Join Date
    Jul 2011
    Posts
    36
    Rep Power
    0

    Default

    Can anyone help me?

  4. #24
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,390
    Rep Power
    25

    Default

    java.io.IOException: could not create audio stream from input stream
    Try another type of file

  5. #25
    seegee is offline Member
    Join Date
    Jul 2011
    Posts
    36
    Rep Power
    0

    Default

    I tried a .wav file and got the same error. The wav file was about 3 seconds long.

  6. #26
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,390
    Rep Power
    25

    Default

    This code works for me:
    Java Code:
            AudioPlayer AP = AudioPlayer.player;
            AudioStream AS;
            AudioData AD;
            ContinuousAudioDataStream loop= null;
            
            try {
               AS = new AudioStream(new FileInputStream("Audio/gong.wav"));
               // mp3 => java.io.IOException: could not create audio stream from input stream
               AD = AS.getData();
               loop = new ContinuousAudioDataStream (AD);
            }catch (IOException error) {error.printStackTrace();}
            
            
           AP.start (loop);

  7. #27
    seegee is offline Member
    Join Date
    Jul 2011
    Posts
    36
    Rep Power
    0

    Default

    Nope, got the same error again. I tried it in my program and In another class alone. I still got the same error :( Is there something wrong with my computer or something?

  8. #28
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,390
    Rep Power
    25

    Default

    Must be something different. What JDK and OS are you on?

  9. #29
    seegee is offline Member
    Join Date
    Jul 2011
    Posts
    36
    Rep Power
    0

    Default

    I am using Java version 1.6.0_26 on Mac OSX 10.7. I was on 10.6 a few days ago but i was getting the same error. (I didn't have to download JDK or Java because it came with my mac)

  10. #30
    seegee is offline Member
    Join Date
    Jul 2011
    Posts
    36
    Rep Power
    0

    Default

    Can anyone who is using mac osx test the code for me?

  11. #31
    seegee is offline Member
    Join Date
    Jul 2011
    Posts
    36
    Rep Power
    0

    Default

    Does anyone have an audio code confirmed working on Mac Osx?

  12. #32
    bigsonny is offline Senior Member
    Join Date
    Nov 2010
    Posts
    164
    Rep Power
    4

    Default

    I really don't know the clear answer to your question, but a really bad advice if you want to get this done is to hack a program that plays sound that was written in Java and see how it's coded. It's bad advice because it's often best to learn linearly as much of the basics as you can before blindly copying the code of others. Other people's code is meant to teach you how to solve problems in a way that has been done by someone else to expand your thinking, but if you don't know the basics, then you're setting yourself up for bad habits....such as using youtube to learn to code Java. Also, JDK 7 is out...

  13. #33
    seegee is offline Member
    Join Date
    Jul 2011
    Posts
    36
    Rep Power
    0

    Default

    I do know the basics to java and this was the only time that I have ever looked on youtube for code. I always code my own stuff, my goal is not to make a good program. My goal is to learn Java and just copying codes all the time (which I don't do) is not the way to learn it. But I will try to get the source code of a program that plays audio.

  14. #34
    bigsonny is offline Senior Member
    Join Date
    Nov 2010
    Posts
    164
    Rep Power
    4

    Default

    Okay. I was just offering some basic advice. If you know the basics, then one of the senior members (well super senior members) may be better suited to point you in the right direction. Hacking is a good way to learn though...! Good luck!

  15. #35
    bigsonny is offline Senior Member
    Join Date
    Nov 2010
    Posts
    164
    Rep Power
    4

Page 2 of 2 FirstFirst 12

Similar Threads

  1. No background in FESM
    By NatureFreshMilk in forum New To Java
    Replies: 2
    Last Post: 07-08-2011, 11:17 AM
  2. How to Run a .exe in background???
    By jazz2k8 in forum New To Java
    Replies: 9
    Last Post: 01-21-2011, 11:27 AM
  3. Background in JFrame ( GUI).
    By Twister03 in forum AWT / Swing
    Replies: 2
    Last Post: 03-12-2009, 03:24 AM
  4. Background image
    By leiferouis in forum New To Java
    Replies: 9
    Last Post: 03-08-2009, 05:49 PM
  5. BackGround & ForeGround
    By hungleon88 in forum Advanced Java
    Replies: 3
    Last Post: 08-31-2008, 07:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •