Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8565411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:25:15+00:00 2026-06-11T17:25:15+00:00

The play method below is from a class which, upon instantiation, reads a .wav

  • 0

The play method below is from a class which, upon instantiation, reads a .wav file into a byte array called data, and stores the sound format in an AudioFormat object called format.

I have a program that calls play from a java.util.Timer. When I go into the folder with all the relevant .class files and I run the program using the command java MainClass, everything works as expected. However, when I put all the .class files in an executable .jar and run the program using the command java -jar MyProgram.jar, sounds played using the play method are cut off after something like 50 to 150 ms.

public void play() throws LineUnavailableException {
    final Clip clip = (Clip)AudioSystem.getLine(new DataLine.Info(Clip.class, format));
    clip.open(format, data, 0, data.length);
    new Thread() {
        public void run() {
            clip.start();
            try {
                Thread.sleep(300); // all sounds are less than 300 ms long
            } catch (InterruptedException ex) { /* i know, i know... */ }
            clip.close();
        }
    }.start();
}

A few comments:

  • I’ve tried increasing the sleep time in the play method up to 1000 ms, with no change in behavior.

  • Timing the Thread.sleep using System.nanoTime confirms that the thread is sleeping exactly as long as expected.

  • Since the sound file to be played is pre-loaded into memory, I don’t think the act of extracting the sound resource from the .jar can be causing the problem.

  • I’ve tried running the program from both inside and outside the jar using the memory pool size options -Xms2m and -Xmx64m (separately), with no change in behavior.

I’m running OpenJDK Java 6 on Ubuntu 11.04. Any idea what’s going on?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:25:17+00:00Added an answer on June 11, 2026 at 5:25 pm

    It is likely the loading of the byte[] that is the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is a snippet from the Adobe Live Docs SampleDataEvent class. It demonstrates how
I have a class something like below, and I used instance variables (array) to
I want to map multiple URLs into an overloaded controller method as below. But
i get the stack below from google play, but i'm not understand why: Source
i try to off a sound effect on my app play method is '
I'm trying to test a model method using Play Framework 2.0 and Specs2. Global.scala
How this UIButton rewind can send notification to UIButton play to perform playpauseaction method
Recently I've been thinking about performance difference between class field members and method variables.
I have a controller that is being called twice from an ActionLink call. My
Below is some code I'm having trouble with. Basically, I'm defining an empty array

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.