Results 1 to 8 of 8

Thread: Looping audio?

  1. #1
    Join Date
    Sep 2010
    Posts
    47
    Rep Power
    0

    Question Looping audio?

    Hi.
    I wonder if there's an easy way of looping audio, currently i use a timer that's on the same lenght as the audio/song, the timer then starts then song again. I've tried adding "ContinuousAudioDataStream" to my code, but i'm getting some weird errors. I'm probably just doing the coding wrong, so if someone could tell me how to add ContinuousAudioDataStream properly, then tell me :)

    Also, is there a way to stop the audio completely, reseting it. If i use "AudioPlayer.player.stop()" it simply stops the song on that certain spot and if i call AudioPlayer.play.start() it starts from the same location of the song..

    EDIT:Is there a simple way to decrease the volume of the audio from within the java application/program?

    Currently i'm using this:
    PHP Code:
    public void music() throws IOException{
    	Toolkit tk = this.getToolkit();
    	InputStream sond = this.getClass().getResourceAsStream("/BGMUSIC2.WAV");
    	AudioStream as = new AudioStream(sond);
    		AudioPlayer.player.start(as);
    	}
    Last edited by AndroidAppNewbie; 03-13-2011 at 04:44 PM.

  2. #2
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    Java Code:
    public void loop() {
           stop();
           if (theData == null) open();
           if (theData != null) {
             ContinuousAudioDataStream cads = new ContinuousAudioDataStream
     (theData);
             AudioPlayer.player.start(cads);
             nowPlaying = cads;
           }
         }
    Source: Java Secrets:Controlling Audio Playback with sun.audio

  3. #3
    Join Date
    Sep 2010
    Posts
    47
    Rep Power
    0

    Default

    I didn't quite understand your coding there ozzyman, could you possibly explain abit more detailed?

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,773
    Blog Entries
    7
    Rep Power
    21

    Default

    What is an AudioPlayer? It is not a class in the standard core distribution.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    Join Date
    Sep 2010
    Posts
    47
    Rep Power
    0

    Default

    AudioPlayer is what it sounds like, it simply plays Audio, the exact way on how it's working i don't really know. I googled around to add sound, i found this was the easiest way of doing it.

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,773
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by AndroidAppNewbie View Post
    AudioPlayer is what it sounds like, it simply plays Audio, the exact way on how it's working i don't really know. I googled around to add sound, i found this was the easiest way of doing it.
    So you're using a third party library. Why don't you stick to the available core libraries, e.g. a AudioClip can easily to what you want.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    Join Date
    Sep 2010
    Posts
    47
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    So you're using a third party library. Why don't you stick to the available core libraries, e.g. a AudioClip can easily to what you want.

    kind regards,

    Jos
    Third party library, i'm not familiar with that, it sounds like something you download, but i haven't. Anyway, if you say that this piece of code is that, then allright. And i've been trying with audio clips aswell, but i didn't get it to work. Will you be kind enough to post a small code example? Or a link to a good tutorial?

  8. #8
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,773
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by AndroidAppNewbie View Post
    Third party library, i'm not familiar with that, it sounds like something you download, but i haven't. Anyway, if you say that this piece of code is that, then allright. And i've been trying with audio clips aswell, but i didn't get it to work. Will you be kind enough to post a small code example? Or a link to a good tutorial?
    I'd simply do something like this:

    Java Code:
    AudioClip clip= Applet.newAudioClip(urlOfAudioFile);
    clip.play();
    // or this:
    clip.loop();
    // or this:
    clip.stop();
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Looping WAY too many times...
    By BariMutation in forum New To Java
    Replies: 10
    Last Post: 10-15-2010, 11:27 AM
  2. Looping
    By Dean29126 in forum New To Java
    Replies: 3
    Last Post: 09-08-2010, 03:01 PM
  3. Advanced Looping
    By nuggetman4 in forum New To Java
    Replies: 1
    Last Post: 05-10-2010, 07:54 AM
  4. Help with While and For Looping
    By gmoney8316 in forum New To Java
    Replies: 2
    Last Post: 03-03-2010, 11:54 PM
  5. Looping Help Please
    By JonnySnip3r in forum New To Java
    Replies: 5
    Last Post: 01-31-2010, 06:57 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
  •