Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 12 of 12

Thread: could not create audio stream from input stream

  1. #1
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default could not create audio stream from input stream

    import java.io.*;
    import sun.audio.*;
     
     
    public class Sample
    {
      public static void main(String[] args)
      throws Exception
      {
     
        String soundFile = "C:\\KKKFOLDER\\samp.wav";
        InputStream in = new FileInputStream(soundFile);
     
     
        AudioStream audioStream = new AudioStream(in);
     
     
        AudioPlayer.player.start(audioStream);
      }
    }
    a simple code that tries to load a wav file into an input stream.
    but no matter what code i tried to run from Google and web resources i always get this error
    could not create audio stream from input stream
    need some precise guide with this one..


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: could not create audio stream from input stream

    Can you include the import statements showing the packages you are using?
    Also please post the full text of the error message.

  3. #3
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: could not create audio stream from input stream

    full text of the error message.
    Exception in thread "main" java.io.IOException: could not create audio stream from input stream
            at sun.audio.AudioStream.<init>(AudioStream.java:65)
            at Sample.main(Sample.java:15)
    Java Result: 1

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: could not create audio stream from input stream

    Can you include the import statements showing the packages you are using?

  5. #5
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: could not create audio stream from input stream

    import java.io.FileInputStream;
    import java.io.InputStream;
    import sun.audio.AudioPlayer;
    import sun.audio.AudioStream;

  6. #6
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: could not create audio stream from input stream

    To get this code to work in Eclipse I had to go to:

    Windows -> Preferences -> Java -> Compiler -> Errors/Warnings

    Deprecated and restricted API -> Forbidden Reference (Access Rules) -> Warning

    (Access restriction: Class is not accessible due to restriction on required library)

    And updated the code to:

    import java.io.FileInputStream;
    import java.io.InputStream;
    import sun.audio.AudioPlayer;
    import sun.audio.AudioStream; 
     
    @SuppressWarnings("restriction")
    public class Sample
    {
      public static void main(String[] args) throws Exception
      { 
        String soundFile = "C:\\samp.wav";
        InputStream in = new FileInputStream(soundFile); 
        AudioStream audioStream = new AudioStream(in); 
        AudioPlayer.player.start(audioStream);
      }
    }

    I downloaded a .wav file as a sample and put it in the C:\ drive.
    When I run the code, it works fine
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  7. #7
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: could not create audio stream from input stream

    Re: could not create audio stream from input stream
    To get this code to work in Eclipse I had to go to:

    Windows -> Preferences -> Java -> Compiler -> Errors/Warnings

    Deprecated and restricted API -> Forbidden Reference (Access Rules) -> Warning
    i saw these statements somewhere in google as well.. perhaps that person encountered some problems with this one using eclipse.. and that person manages to compensate with the issue.

    but the problem is im using netbeans.. but hey! thanks sir.. ill try to apply the same thing on my IDE to resolve it,

    and i think i really have to apply that thing on my IDE as well.. i tried to copy the code of yours.. but i still get the same erro
    Last edited by chronoz13; May 31st, 2011 at 08:56 AM.

  8. #8
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: could not create audio stream from input stream

    by the way.. i don't have any idea where to and what to find in my IDE to set up the same thing...
    Windows -> Preferences -> Java -> Compiler -> Errors/Warnings

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: could not create audio stream from input stream

    I don't use an IDE. This code works on my XP system:
    import java.io.FileInputStream;
    import java.io.InputStream;
    import sun.audio.AudioPlayer;    //warning: sun.audio.AudioPlayer is Sun proprietary API and may be removed in a future release
    import sun.audio.AudioStream; 
     
    @SuppressWarnings("restriction") 
    public class SampleAudioPlayer
    {
      public static void main(String[] args)   throws Exception    {
     
        String soundFile = "Audio/1-welcome.wav";
        InputStream in = new FileInputStream(soundFile);
     
        AudioStream audioStream = new AudioStream(in);
     
        AudioPlayer.player.start(audioStream);
      }
    }

  10. #10
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: could not create audio stream from input stream

    this is one of the hardes problem i need to resolve in the sound part of my game... ive been searching the whole web.. as far as i can go.. but i ended up messing things... i kept narrowing things down.. from what type of music file and codes im going to implement...
    i have decided to use wav.. because its a bit more little than mp3... and i got some problems using mp3 files...

    if you can guide me how can i modify the Error/Warning Restriction things on my IDE like the one above done in eclipse i may solve the problem... ive been searching the google for using some keyword to set up those things... but still .. i ended up messing around...

  11. #11
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: could not create audio stream from input stream

    im really messed up and dont know how to apply this
    Windows -> Preferences -> Java -> Compiler -> Errors/Warnings

    Deprecated and restricted API -> Forbidden Reference (Access Rules) -> Warning
    on netbeans... and im still getting that exception no matter what i do...

    i searced the google with keywords like "preferece settings" "restriction settings setup in netbeans", "error/warnings setup in netbeans" but it doesnt give me any useful reference.

  12. #12
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: could not create audio stream from input stream

    i tried to suppress a depcrecation instead of restriction
     @SupressWarnings("deprecation")

    i found something on a particular project setup on my projects..

    right click projects > properties > build > compiling > a check box "Report uses of deprecated APIs"

    i checked that box.. still nothing happens
    Last edited by chronoz13; June 2nd, 2011 at 02:12 AM.

Similar Threads

  1. Read stream of data
    By mapred in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: October 26th, 2012, 12:38 PM
  2. UTF - 8 / Byte Stream
    By JavaCODER in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: October 16th, 2010, 02:26 PM
  3. Stream Tokenizer
    By x3rubiachica3x in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: October 12th, 2010, 01:05 PM
  4. url input stream returning blank
    By yo99 in forum File I/O & Other I/O Streams
    Replies: 7
    Last Post: June 2nd, 2010, 08:14 PM
  5. Client input Stream
    By gisler in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: December 19th, 2009, 09:30 PM