Sunday, April 5, 2015

Simple Wave File Player


This post presents a simple Wave File Player written in Java, using the sampled sound API. Since we are not using JavaFX, it will not support the mp3 format.


We will be using API from the javax.sound.sampled package. Hence we make the following imports at the beginning of the program.
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;

Progress bar

We will use a JSlider as a progress bar. The scale are from 0 to 10000, which is simple to represent 0 to 100% with two decimal place. To update the progress, the following method will be invoked by a Swing Timer on every 30ms.

Sample Wave File

  epic_loop.wav : Orchestral Adventure by RevampedPRO, CC BY 3.0 license 

  twoTone2.wav : "63 Digital sound effects" by Kenney, CC0 license,
The wave files are inside a github project. Follow the following link to download the project as a zip file.

Source Code

No comments:

Post a Comment