carookee - group communication for you
Home / JavaForum / Java allgemein
Infos   |   Features   |   Gold-Edition   |   Kundenservice   
java
  Übersicht
  Forum
Beginner
Java allgemein
JDBC
JNI
Networking
Online-Ressourcen
Swing + AWT
XML
Meckerecke
  Mitglieder
LOGIN





· Passwort vergessen
· Kostenlos anmelden
  Information
  Demo
  Features
  Im Vergleich
  Anmeldung
SUCHE
Beiträge, Foren oder Verfasser finden:
  Kundenservice
  Impressum
  Datenschutz
  AGB
Status
3.200 User online
0 User eingeloggt
 

Beiträge
   Antworten     Neuer Beitrag    

Beitrag 1534 von 2212 (69%) |<   <   >   >|

Autor Timo S
Datum 31.08.04, 08:08
Betreff Probleme mit Soundausgabe


Hallo,
ich haenge nun seit 3 Tagen an einer Sache.
Und zwar der Sound ausgabe von Wav-Dateien in einer Applikation (also KEIN APLETT!).

Ich bekomme zwar keine Fehler aber Sound kommt auch nicht.
den folgenden Code teste ich durch eine Eingabe in die Kommandozeile.

Bitte helft mir oder schickt mir code der bei euch definitiv waves abspielt. ;)

import java.io.*;
import javax.sound.sampled.*;

public class Sounds {
    
    static AudioInputStream ais;
    static Clip clip;
    
    public static void playSampleFile(String name, float pan, float gain) throws Exception {
        
        // AudioInputStream öffnen
        System.out.println("Start");
        try{
             ais = AudioSystem.getAudioInputStream(new File(name));
            System.out.println("1A");
        }
        catch (IOException e){
            System.out.println("IOException!");
            System.out.println("1B");
        }
        catch (UnsupportedAudioFileException e){
            System.out.println("UnsupportedAudioFileException!");
            System.out.println("1C");
        }
        
        AudioFormat format = ais.getFormat();
        //ALAW/ULAW samples in PCM konvertieren
        if ((format.getEncoding() == AudioFormat.Encoding.ULAW) ||
        (format.getEncoding() == AudioFormat.Encoding.ALAW)){
            AudioFormat tmp = new AudioFormat(
            AudioFormat.Encoding.PCM_SIGNED,
            format.getSampleRate(),
            format.getSampleSizeInBits() * 2,
            format.getChannels(),
            format.getFrameSize() * 2,
            format.getFrameRate(),
            true
            );
            ais = AudioSystem.getAudioInputStream(tmp, ais);
            format = tmp;
        }
        // Clip erzeugen und öffnen
        DataLine.Info info = new DataLine.Info(
        Clip.class,format,((int) ais.getFrameLength() * format.getFrameSize()));
        try{
            clip = (Clip)AudioSystem.getLine(info);
            clip.open(ais);
            System.out.println("2A");
        }
        catch (IOException e){
            System.out.println("IOException!");
            System.out.println("2B");
        }
        catch (LineUnavailableException e){
            System.out.println("LineUnavailableException!");
            System.out.println("2C");
        }
        
        // PAN einstellen
        FloatControl panControl = (FloatControl)clip.getControl(FloatControl.Type.PAN);
        panControl.setValue(pan);
        //MASTER_GAIN einstellen
        FloatControl gainControl = (FloatControl)clip.getControl(FloatControl.Type.MASTER_GAIN);
        gainControl.setValue(gain);
        
        //Clip abspielen
        System.out.println("vor start");
        System.out.println("Framelength: "+clip.getFrameLength());
        System.out.println("Frameposition: "+clip.getFramePosition());
        System.out.println("Format: "+clip.getFormat());
        System.out.println("Active: "+clip.isActive());
        System.out.println("Open: "+clip.isOpen());
        System.out.println("Level: "+clip.getLevel());
        clip.start();
        while(true) {
            try {
                Thread.sleep(100);
                }catch(Exception e) {
                //nothing
            }
            if(!clip.isRunning()) {
                break;
            }
        }
        clip.stop();
        System.out.println("nach start");
        clip.close();
    }
    
    public static void main(String[] args){
        try{
            playSampleFile("c:/move.wav",Float.parseFloat("5"),Float.parseFloat("5"));
        }
        catch(Exception e){
            e.printStackTrace();
            System.exit(1);
        }
        System.exit(0);
    }
}



Diskussionsverlauf:
Probleme mit Soundausgabe
    Re: Probleme mit Soundausgabe
        Re: Probleme mit Soundausgabe
            Re: Probleme mit Soundausgabe

 Auf diesen Beitrag antworten
 Neuen Beitrag verfassen


|<   <   >   >|

                                                                                                                                                                                                                           

Impressum  · Datenschutz  · AGB  · Infos  · Presse
Ein modernes Forum: teamturn.com