Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hendriks73/audioplayer4j
Java Audioplayer
https://github.com/hendriks73/audioplayer4j
audio flac linux macos mp3 player windows
Last synced: about 9 hours ago
JSON representation
Java Audioplayer
- Host: GitHub
- URL: https://github.com/hendriks73/audioplayer4j
- Owner: hendriks73
- License: lgpl-2.1
- Created: 2021-11-15T13:04:09.000Z (almost 3 years ago)
- Default Branch: dev
- Last Pushed: 2023-05-10T15:02:52.000Z (over 1 year ago)
- Last Synced: 2024-09-24T21:02:41.486Z (3 days ago)
- Topics: audio, flac, linux, macos, mp3, player, windows
- Language: Java
- Homepage:
- Size: 3.16 MB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![LGPL 2.1](https://img.shields.io/badge/License-LGPL_2.1-blue.svg)](https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.tagtraum/audioplayer4j/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.tagtraum/audioplayer4j)
[![Build and Test](https://github.com/hendriks73/audioplayer4j/workflows/Build%20and%20Test/badge.svg)](https://github.com/hendriks73/audioplayer4j/actions)
[![CodeCov](https://codecov.io/gh/hendriks73/audioplayer4j/branch/main/graph/badge.svg?token=IBVAHZW5DZ)](https://codecov.io/gh/hendriks73/audioplayer4j/branch/main)# audioplayer4j
Simply plays audio.
## Usage
To play an audio file, simply call the
[AudioPlayer's](https://hendriks73.github.io/audioplayer4j/tagtraum.audioplayer4j/com/tagtraum/audioplayer4j/AudioPlayer.html)
[play(uri)](https://hendriks73.github.io/audioplayer4j/tagtraum.audioplayer4j/com/tagtraum/audioplayer4j/AudioPlayer.html#play(java.net.URI))
method:```java
AudioPlayer.play(someURI);
```Playback will start asynchronously.
Here's a more comprehensive example, using the
[AudioPlayerFactory](https://hendriks73.github.io/audioplayer4j/tagtraum.audioplayer4j/com/tagtraum/audioplayer4j/AudioPlayerFactory.html):```java
import com.tagtraum.audioplayer4j.*;
import java.util.concurrent.CountDownLatch;
import java.net.URI;public class AudioplayerExample {
public static void main(final String[] args) throws Exception {
// open a player object for the given URI
// do so, with try-resource management
try (final AudioPlayer player = AudioPlayerFactory.open(new URI(args[0]))) {// add a listener, so that we are notified,
// once playback has stopped.
final CountDownLatch finished = new CountDownLatch(1);
player.addAudioPlayerListener(new AudioPlayerListener() {
@Override
public void started(final AudioPlayer audioPlayer, final URI uri) {
}@Override
public void finished(final AudioPlayer audioPlayer, final URI uri, final boolean endOfMedia) {
finished.countDown();
}
});// start playback
player.play();
// wait until playback has finished.
finished.await();
}
}
}
```If you'd like to be notified about playback process, pause events etc.,
just add a corresponding `PropertyListener`. Note that all events are
posted on the event dispatch thread (EDT).## Installation
*audioplayer4j* is released via [Maven](https://maven.apache.org).
You can install it using the following dependency:```xml
com.tagtraum
audioplayer4j-complete
```
Without further packages, *audioplayer4j* works very well on macOS and,
but has only mediocre codec (audio format) support on other platforms.
That said, *audioplayer4j* plays very well with others. You can
play a wide variety of audio formats by installing a suitable
`javax.sound.sampled` package or JavaFX modules.
For details, please see below.## Leveraging javax.sound.sampled Packages
The Java sampled sound API uses a service provider architecture, which can be implemented
by third parties (see [javax.sound.sampled.spi](https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/sound/sampled/spi/package-summary.html)).
Any such providers may be picked up and used for playback by *audioplayer4j*.Examples are:
- [FFSampledSP](https://github.com/hendriks73/ffsampledsp), an FFmpeg based provider (Ubuntu, macOS, Windows)
- [CASampledSP](https://github.com/hendriks73/casampledsp), a Core Audio-based provider (macOS only)For example, to add *FFSampledSP*, simply use this dependency:
```xml
com.tagtraum
ffsampledsp-complete
```
## Taking Advantage of JavaFX
In order to allow *audioplayer4j* to utilize JavaFX libraries,
you may also want to add the following dependencies:```xml
org.openjfx
javafx-base
org.openjfx
javafx-swing
org.openjfx
javafx-media
org.openjfx
javafx-graphics
```
## Java Module
*audioplayer4j* is shipped as a Java module
(see [JPMS](https://en.wikipedia.org/wiki/Java_Platform_Module_System))
with the name `tagtraum.audioplayer4j`.## API
You can find the complete API [here](https://hendriks73.github.io/audioplayer4j/).