Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-11-2009, 12:05 AM   #1
Registered: Sep 2003
Location: USA
Distribution: Slackware (Multiple Versions)
Posts: 455

Rep: Reputation: 31
Playing a wav in java

Here is my code:
import java.util.Scanner;

public class MusicPlayer {

    private String filename;

    public MusicPlayer(String filename) {
        this.filename = filename;

    public void play() {
        try {
                InputStream in = new FileInputStream(filename);
                AudioStream as = new AudioStream(in);

        } catch (IOException e) {
	public static void main(String[] args)
		System.out.println("Audiofile: ");
		Scanner kb = new Scanner(;
		String afilename = kb.nextLine();
		new MusicPlayer(afilename);
All this does is ask for a wav file to play, and its SUPPOSED to play the wave file. Can someone please tell me what is wrong with this? It compiles, runs, but doesnt play the file. When it runs it doesnt throw any exceptions or anything, it just exits.

Any Ideas?

Old 05-11-2009, 12:19 AM   #2
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
My guess is that maybe the Java libraries aren't talking to your PC's audio hardware. Look here for some troubleshooting tips:

'Hope that helps .. PSM


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Playing sounds (wav) in xchat profster Linux - Newbie 1 01-07-2008 01:19 PM
Playing wav files - and then some! srlevitt Programming 1 06-12-2007 02:37 PM
Playing WAV files in SUSE 9.3-64 riba43 SUSE / openSUSE 2 08-15-2005 10:31 AM
playing wav files bdu Linux - General 2 02-22-2002 10:48 PM
Playing wav files bdu Linux - General 1 02-07-2002 04:22 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:51 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration