-
- All Superinterfaces:
- AutoCloseable
- All Known Subinterfaces:
- Clip, DataLine, Mixer, Port, SourceDataLine, TargetDataLine
public interface Line extends AutoCloseable
TheLine
interface represents a mono or multi-channel audio feed. A line is an element of the digital audio "pipeline," such as a mixer, an input or output port, or a data path into or out of a mixer.A line can have controls, such as gain, pan, and reverb. The controls themselves are instances of classes that extend the base
class. TheControl
Line
interface provides two accessor methods for obtaining the line's controls:
returns the entire set, andgetControls
returns a single control of specified type.getControl
Lines exist in various states at different times. When a line opens, it reserves system resources for itself, and when it closes, these resources are freed for other objects or applications. The
method lets you discover whether a line is open or closed. An open line need not be processing data, however. Such processing is typically initiated by subinterface methods such asisOpen()
andSourceDataLine.write
.TargetDataLine.read
You can register an object to receive notifications whenever the line's state changes. The object must implement the
interface, which consists of the single methodLineListener
. This method will be invoked when a line opens and closes (and, if it's aupdate
DataLine
, when it starts and stops).An object can be registered to listen to multiple lines. The event it receives in its
update
method will specify which line created the event, what type of event it was (OPEN
,CLOSE
,START
, orSTOP
), and how many sample frames the line had processed at the time the event occurred.Certain line operations, such as open and close, can generate security exceptions if invoked by unprivileged code when the line is a shared audio resource.
- Since:
- 1.3
- See Also:
LineEvent
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface and Description static class
Line.Info
ALine.Info
object contains information about a line.
-
Method Summary
Methods Modifier and Type Method and Description void
addLineListener(LineListener listener)
Adds a listener to this line.void
close()
Closes the line, indicating that any system resources in use by the line can be released.Control
getControl(Control.Type control)
Obtains a control of the specified type, if there is any.Control[]
getControls()
Obtains the set of controls associated with this line.Line.Info
getLineInfo()
Obtains theLine.Info
object describing this line.boolean
isControlSupported(Control.Type control)
Indicates whether the line supports a control of the specified type.boolean
isOpen()
Indicates whether the line is open, meaning that it has reserved system resources and is operational, although it might not currently be playing or capturing sound.void
open()
Opens the line, indicating that it should acquire any required system resources and become operational.void
removeLineListener(LineListener listener)
Removes the specified listener from this line's list of listeners.
-
-
-
Method Detail
-
getLineInfo
Line.Info getLineInfo()
Obtains theLine.Info
object describing this line.- Returns:
- description of the line
-
open
void open() throws LineUnavailableException
Opens the line, indicating that it should acquire any required system resources and become operational. If this operation succeeds, the line is marked as open, and anOPEN
event is dispatched to the line's listeners.Note that some lines, once closed, cannot be reopened. Attempts to reopen such a line will always result in an
LineUnavailableException
.Some types of lines have configurable properties that may affect resource allocation. For example, a
DataLine
must be opened with a particular format and buffer size. Such lines should provide a mechanism for configuring these properties, such as an additionalopen
method or methods which allow an application to specify the desired settings.This method takes no arguments, and opens the line with the current settings. For
andSourceDataLine
objects, this means that the line is opened with default settings. For aTargetDataLine
, however, the buffer size is determined when data is loaded. Since this method does not allow the application to specify any data to load, an IllegalArgumentException is thrown. Therefore, you should instead use one of theClip
open
methods provided in theClip
interface to load data into theClip
.For
DataLine
's, if theDataLine.Info
object which was used to retrieve the line, specifies at least one fully qualified audio format, the last one will be used as the default format.- Throws:
IllegalArgumentException
- if this method is called on a Clip instance.LineUnavailableException
- if the line cannot be opened due to resource restrictions.SecurityException
- if the line cannot be opened due to security restrictions.- See Also:
close()
,isOpen()
,LineEvent
,DataLine
,Clip.open(AudioFormat, byte[], int, int)
,Clip.open(AudioInputStream)
-
close
void close()
Closes the line, indicating that any system resources in use by the line can be released. If this operation succeeds, the line is marked closed and aCLOSE
event is dispatched to the line's listeners.- Specified by:
close
in interfaceAutoCloseable
- Throws:
SecurityException
- if the line cannot be closed due to security restrictions.- See Also:
open()
,isOpen()
,LineEvent
-
isOpen
boolean isOpen()
Indicates whether the line is open, meaning that it has reserved system resources and is operational, although it might not currently be playing or capturing sound.
-
getControls
Control[] getControls()
Obtains the set of controls associated with this line. Some controls may only be available when the line is open. If there are no controls, this method returns an array of length 0.- Returns:
- the array of controls
- See Also:
getControl(javax.sound.sampled.Control.Type)
-
isControlSupported
boolean isControlSupported(Control.Type control)
Indicates whether the line supports a control of the specified type. Some controls may only be available when the line is open.- Parameters:
control
- the type of the control for which support is queried- Returns:
true
if at least one control of the specified type is supported, otherwisefalse
.
-
getControl
Control getControl(Control.Type control)
Obtains a control of the specified type, if there is any. Some controls may only be available when the line is open.- Parameters:
control
- the type of the requested control- Returns:
- a control of the specified type
- Throws:
IllegalArgumentException
- if a control of the specified type is not supported- See Also:
getControls()
,isControlSupported(Control.Type control)
-
addLineListener
void addLineListener(LineListener listener)
Adds a listener to this line. Whenever the line's status changes, the listener'supdate()
method is called with aLineEvent
object that describes the change.- Parameters:
listener
- the object to add as a listener to this line- See Also:
removeLineListener(javax.sound.sampled.LineListener)
,LineListener.update(javax.sound.sampled.LineEvent)
,LineEvent
-
removeLineListener
void removeLineListener(LineListener listener)
Removes the specified listener from this line's list of listeners.- Parameters:
listener
- listener to remove- See Also:
addLineListener(javax.sound.sampled.LineListener)
-
-
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 11/06/2005 gemaakt, de laatste keer de 04/03/2020 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-rf-javax/sound/sampled/line.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.