Giter VIP home page Giter VIP logo

aria's Introduction

aria

Read this in other languages: 简体中文.
Aria is a light-weight java sound system designed to be used in game develop. It's also contain spring support so it can be easily used in a spring application.

The project aim

The aim of aria is provide a light-weight and reliable solution for sound play in game dev.

  • Music for common background music.
  • Sound for sound effect.
  • Based on the SPI decoder,the system can support wav\mp3\ogg now,and you can include many other format like FLAC easily.
  • Many other features for game dev in the future.

Design concept

There are two main abstractions in the system.The Music and Sound.

  • Music
    The Music is defined as the only one main theme in a scene.Usually a music is long enough so we need load a bit and play for each time.
    The api of Music is like init,load(loop),pause,stop etc. The relevant of Music is MusicPlayer class.

  • Sound
    The Sound is defined as sounds that trigged by some relevant events,which means there are lot's of same or different sounds can be played at one time.
    Compare with music,a sound is short enough so we load them all into memory.
    The api of Sound is like play,loop(for many conditions).The sound playing is also optimized for concurrent environment.
    The relevant of Sound is SondFactory class and Sound class,all the api in Sound are thread-safe.

Get the latest release

You need at last java 1.8 to use this system.
The project is hosted in maven central now.
Maven Central

<dependency>
    <groupId>com.thrblock.aria</groupId>
    <artifactId>aria-core</artifactId>
    <version>1.1.0</version>
</dependency>

How to use

There are two main plans,using spring framework or not.

  • Plan A - Using spring framework
    When you want to use java to develop a game,I strong recommand you using a framework to control the lifecycle of you game components like spring
    All we need to do is config a componet-scan,using xml for example.
 <beans xmlns="...">
     <!-- aria sound components -->
     <context:component-scan base-package="com.thrblock.aria" />
 </beans>

And then inject in you class,using @Autowired for example.

 @Component
 public class YourGameComponent {
     @Autowired
     MusicPlayer player;
        
     public void whenYourComponentInit() {
         player.initMusic(new File("./BackGroundMusic.mp3"));
     }
     
     public void whenYourComponentActivited() {
         player.play(-1);//loop forever until stop.
     }
     
     public void whenYourComponentStop() {
         player.stop();
     }
 }
  • Plan B - without spring
    Without spring context so we need control lifecycle manuly
 public class MusicDemo {
     public static void main(String[] args) throws InterruptedException {
         MusicPlayer player = new MusicPlayer(new SPIDecoder());
         player.initMusic(new File("./BackGroundMusic.mp3"));
         player.play(-1);
         Thread.sleep(5000);
         player.stop();
         player.destroy();//do not forget this.
     }
 }

Others

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.