WAV Abspielen

flipsie

Mitglied
Hallo Leute,

ich bräuchte mal eure hilfe :)
Ich wollte ein Programm schreiben das ein oder 2 Lieder abspielt.
Nur er zeigt mir Fehler an mit denen ich nix anfangen kann:(
Vielleicht könntet Ihr mir helfen?:)
Hoffe bekommt keinen schlag :D

Erklärung:
Das Rot markierte, markiert er bei mir rot:(
Habe nur eine klasse die heißt "Sound.java"

hier ist der Code:

import java.awt.event.*;

import javax.swing.*;
import sun.audio.*;
import java.io.*;
public class Sound {

public static void main(String[] args)
{
JFrame frame=new JFrame();
frame.setSize(200,200);
JButton button=new JButton("Click me");
frame.add(button);
button.addActionListener(new AL());
frame.show(true);
}
public static class AL implements ActionListener{
public final void achtionPerformed(ActionEvent e){
music();
}

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub

}
}
public static void music()
{
AudioPlayer MGP = AudioPlayer.player;
AudioStream BGM;
AudioData MD;
ContinuousAudioDataStream loop=null;

try{
BGM=new AudioStream(new FileInputStream("auto.wav"));
MD= BGM.getData();
loop=new ContinuousAudioDataStream(MD);
}catch(IOException error){}

MGP.start(loop);
}

}

wäre toll wenn Ihr mir helfen könntet :)

Gruss Philipp
 
M

Marcinek

Gast
Du könntest deinen Quellcode in Java Tags packen, dann würdest du es sehen.

Pause und so:
Bestimmt ist das einfach, aber da müsste ich googeln um zu sehen, wie das DAMIT funktioniert. Habe das noch nie benötigt.
 
Zuletzt bearbeitet von einem Moderator:
M

Marcinek

Gast
Ohh mein Gott. *Shendon*

Naja vielleicht wird es klarer, wenn du dein nächsten Post machst.

---

Ich habe mal deinen Quellcode kompiliert. => Keine Probleme.

Merk dir schon mal für die Zukunft: Wenn Fehler auftauchen, dann schreib auch, welche Fehler kommen. :bahnhof:
 

flipsie

Mitglied
Oh sorry! Ich hab hier mal die Probleme die er zeigt kopiert.

Description Resource Path Location Type
Access restriction: The constructor AudioStream(InputStream) is not accessible due to restriction on required library C:\Program Files\Java\jre7\lib\rt.jar Sound.java /MP44/src line 36 Java Problem

Access restriction: The constructor ContinuousAudioDataStream(AudioData) is not accessible due to restriction on required library C:\Program Files\Java\jre7\lib\rt.jar Sound.java /MP44/src line 38 Java Problem

Access restriction: The field player from the type AudioPlayer is not accessible due to restriction on required library C:\Program Files\Java\jre7\lib\rt.jar Sound.java /MP44/src line 30 Java Problem

Access restriction: The method getData() from the type AudioStream is not accessible due to restriction on required library C:\Program Files\Java\jre7\lib\rt.jar Sound.java /MP44/src line 37 Java Problem

Access restriction: The method start(InputStream) from the type AudioPlayer is not accessible due to restriction on required library C:\Program Files\Java\jre7\lib\rt.jar Sound.java /MP44/src line 41 Java Problem

Access restriction: The type AudioData is not accessible due to restriction on required library C:\Program Files\Java\jre7\lib\rt.jar Sound.java /MP44/src line 32 Java Problem

Access restriction: The type AudioPlayer is not accessible due to restriction on required library C:\Program Files\Java\jre7\lib\rt.jar Sound.java /MP44/src line 30 Java Problem

Access restriction: The type AudioPlayer is not accessible due to restriction on required library C:\Program Files\Java\jre7\lib\rt.jar Sound.java /MP44/src line 30 Java Problem

Access restriction: The type AudioStream is not accessible due to restriction on required library C:\Program Files\Java\jre7\lib\rt.jar Sound.java /MP44/src line 31 Java Problem

Access restriction: The type AudioStream is not accessible due to restriction on required library C:\Program Files\Java\jre7\lib\rt.jar Sound.java /MP44/src line 36 Java Problem

Access restriction: The type ContinuousAudioDataStream is not accessible due to restriction on required library C:\Program Files\Java\jre7\lib\rt.jar Sound.java /MP44/src line 33 Java Problem

Access restriction: The type ContinuousAudioDataStream is not accessible due to restriction on required library C:\Program Files\Java\jre7\lib\rt.jar Sound.java /MP44/src line 38 Java Problem

Er zeigt mir das Fenster an wo "Click me" drin steht aber spielt nix ab :(
 
M

Marcinek

Gast
Du benutzt ein Framework, wie GWT oder Java ME, und dieses verbietet es dir teile der Java API zu nutzen.
 

flipsie

Mitglied
hey,

okay.
Wie könnt ich den Code umändern das er einwandfrei funktioniert?
Oder könntet Ihr mir da was zusammen schreiben?

gruss Philipp
 

flipsie

Mitglied
Hey,

habe ich schonmal probiert :)
da zeigt es bei mir
"Play usage: java Play <sound file names>*"
das an und weis nich wie ich nen lied abspielen kann.
 

flipsie

Mitglied
hey,

hab nochmal einbisschen rum geschaut.
Bin jetzt soweit dass der Quellcode keine Probleme anzeigt.
Er zeigt unten ledeglich das
"Play usage:java Play <sound file names>*" an. Und spielt den sound nich.
Habe ich vielleicht irgendwo was vergessen?


import java.io.File;
import java.io.IOException;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.FloatControl;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;

public class Play {
/** Plays audio from given file names. */
public static void main( String [] args ) {
// Check for given sound file names.
if (args.length < 1) {
System.out.println( "Play usage:" );
System.out.println( "\tjava Play <sound file names>*" );
System.exit( 0 );
}

// Process arguments.
for (int i = 0; i < args.length; i++ )
playAudioFile( args[ i ] );

// Must exit explicitly since audio creates non-daemon threads.
System.exit( 0 );
} // main

public static void playAudioFile( String fileName ) {
File soundFile = new File( "C:\\Users\\Philipp\\workspace\\MP45\\mamaauto.wav " );

try {
// Create a stream from the given file.
// Throws IOException or UnsupportedAudioFileException
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream( soundFile );
// AudioSystem.getAudioInputStream( inputStream ); // alternate audio stream from inputstream
playAudioStream( audioInputStream );
} catch ( Exception e ) {
System.out.println( "Problem with file " + fileName + ":" );
e.printStackTrace();
}
} // playAudioFile

/** Plays audio from the given audio input stream. */
public static void playAudioStream( AudioInputStream audioInputStream ) {
// Audio format provides information like sample rate, size, channels.
AudioFormat audioFormat = audioInputStream.getFormat();
System.out.println( "Play input audio format=" + audioFormat );

// Open a data line to play our type of sampled audio.
// Use SourceDataLine for play and TargetDataLine for record.
DataLine.Info info = new DataLine.Info( SourceDataLine.class, audioFormat );
if ( !AudioSystem.isLineSupported( info ) ) {
System.out.println( "Play.playAudioStream does not handle this type of audio on this system." );
return;
}

try {
// Create a SourceDataLine for play back (throws LineUnavailableException).
SourceDataLine dataLine = (SourceDataLine) AudioSystem.getLine( info );
// System.out.println( "SourceDataLine class=" + dataLine.getClass() );

// The line acquires system resources (throws LineAvailableException).
dataLine.open( audioFormat );

// Adjust the volume on the output line.
if( dataLine.isControlSupported( FloatControl.Type.MASTER_GAIN ) ) {
FloatControl volume = (FloatControl) dataLine.getControl( FloatControl.Type.MASTER_GAIN );
volume.setValue( 100.0F );
}

// Allows the line to move data in and out to a port.
dataLine.start();

// Create a buffer for moving data from the audio stream to the line.
int bufferSize = (int) audioFormat.getSampleRate() * audioFormat.getFrameSize();
byte [] buffer = new byte[ bufferSize ];

// Move the data until done or there is an error.
try {
int bytesRead = 0;
while ( bytesRead >= 0 ) {
bytesRead = audioInputStream.read( buffer, 0, buffer.length );
if ( bytesRead >= 0 ) {
// System.out.println( "Play.playAudioStream bytes read=" + bytesRead +
// ", frame size=" + audioFormat.getFrameSize() + ", frames read=" + bytesRead / audioFormat.getFrameSize() );
// Odd sized sounds throw an exception if we don't write the same amount.
int framesWritten = dataLine.write( buffer, 0, bytesRead );
}
} // while
} catch ( IOException e ) {
e.printStackTrace();
}

System.out.println( "Play.playAudioStream draining line." );
// Continues data line I/O until its buffer is drained.
dataLine.drain();

System.out.println( "Play.playAudioStream closing line." );
// Closes the data line, freeing any resources such as the audio device.
dataLine.close();
} catch ( LineUnavailableException e ) {
e.printStackTrace();
}
} // playAudioStream
} // Play
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
M Audio Track einer Musik CD abspielen mittels vlcj-Bibliothek Spiele- und Multimedia-Programmierung 0
P .Wav Datei vor main-Methode abspielen? Spiele- und Multimedia-Programmierung 9
S AAC abspielen Spiele- und Multimedia-Programmierung 9
MABY Eine mp3 Datei in Java abspielen Spiele- und Multimedia-Programmierung 14
S Sounds abspielen Spiele- und Multimedia-Programmierung 11
Blender3D VLCJ Video lässt sich nicht mehr abspielen nach mysql Installation Spiele- und Multimedia-Programmierung 1
K Sound im loop abspielen, wenn boolscher wert true ist Spiele- und Multimedia-Programmierung 3
J Musik abspielen Spiele- und Multimedia-Programmierung 11
C Midi abspielen und Listener anmelden? Spiele- und Multimedia-Programmierung 1
I Sound Dateien abspielen Spiele- und Multimedia-Programmierung 9
C Sound einfügen und abspielen Spiele- und Multimedia-Programmierung 6
H wma Datei abspielen: java.io.IOException: Resetting to invalid mark Spiele- und Multimedia-Programmierung 11
F Einen Sound mit veränderter Tonhöhe und Geschwindigkeit abspielen - Hilfe erbeten Spiele- und Multimedia-Programmierung 29
F Problem mit dem Abspielen von byte[] (Audioprogrammierung) Spiele- und Multimedia-Programmierung 2
C Problem mit Abspielen von Audio-Dateien Spiele- und Multimedia-Programmierung 3
S Sounds abspielen, ohne sie jedesmal neu zu laden Spiele- und Multimedia-Programmierung 8
P Video in JAVA abspielen,... Spiele- und Multimedia-Programmierung 3
T Sound schneller abspielen Spiele- und Multimedia-Programmierung 4
S Uneffizientes Abspielen von Sounds?! Spiele- und Multimedia-Programmierung 4
Guybrush Threepwood Beste Möglichkeit zum Abspielen von MP3 Spiele- und Multimedia-Programmierung 3
StrikeTom .gif animation als image abspielen Spiele- und Multimedia-Programmierung 2
W CannotRealizeException (jmf) beim abspielen eines liedes Spiele- und Multimedia-Programmierung 3
P Sound auf zwei Lautsprechern getrennt abspielen Spiele- und Multimedia-Programmierung 9
A wav datei aus jar Abspielen Spiele- und Multimedia-Programmierung 7
N Totaler Absturz beim mehrmaligen Abspielen von Sounds Spiele- und Multimedia-Programmierung 5
N bei abspielen der wav datei fehler Spiele- und Multimedia-Programmierung 6
H JMF - Video Abspielen Spiele- und Multimedia-Programmierung 12
R Wave-Datei mit JLayer abspielen Spiele- und Multimedia-Programmierung 4
B videos abspielen Spiele- und Multimedia-Programmierung 2
B Frage zum Abspielen von Sounddateien Spiele- und Multimedia-Programmierung 2
0 Crashes beim Abspielen von Sounds unter Win98 Spiele- und Multimedia-Programmierung 12
G Abspielen von Sounds in Java3D Spiele- und Multimedia-Programmierung 13

Ähnliche Java Themen

Neue Themen


Oben