LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


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

Rep: Reputation: 31
Playing a wav in java


Here is my code:
Code:
import sun.audio.*;
import java.io.*;
import java.util.Scanner;

public class MusicPlayer {

    private String filename;

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

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

        } catch (IOException e) {
                e.printStackTrace();
        }          
    }
	
	public static void main(String[] args)
	{
		System.out.println("Audiofile: ");
		Scanner kb = new Scanner(System.in);
		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?

Thanks
 
Old 05-11-2009, 12:19 AM   #2
paulsm4
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:

http://java.sun.com/javase/6/webnote...tml/sound.html

'Hope that helps .. PSM
 
  


Reply


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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

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