Sunday, April 5, 2015

Simple Wave File Player

Introduction

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.

Import

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 
                  http://opengameart.org/content/orchestral-adventure 

  twoTone2.wav : "63 Digital sound effects" by Kenney, CC0 license, 
    http://opengameart.org/content/63-digital-sound-effects-lasers-phasers-space-etc
The wave files are inside a github project. Follow the following link to download the project as a zip file.
https://github.com/macteki/WavePlayer

Source Code

No comments:

Post a Comment