forked from libgdx/libgdx
-
Notifications
You must be signed in to change notification settings - Fork 0
Streaming music
badlogic edited this page Sep 14, 2013
·
1 revision
For any sound that's longer than a few seconds it is preferable to stream it from disk instead of fully loading it into RAM. Libgdx provides a Music interface that lets you do that.
To load a Music instance we can do the following:
Music music = Gdx.audio.newMusic(Gdx.files.internal("data/mymusic.mp3"));
This loads an MP3 file called "mymusic.mp3"
from the internal directory data
.
Playing back the music instance works as follows:
music.play();
Of course you can set various playback attributes of the Music
instance:
music.setVolume(0.5f); // sets the volume to half the maximum volume
music.setLooping(true); // will repeat playback until music.stop() is called
music.stop(); // stops the playback
music.pause(); // pauses the playback
music.play(); // resumes the playback
boolean isPlaying = music.isPlaying(); // obvious :)
boolean isLooping = music.isLooping(); // obvious as well :)
float position = music.getPosition(); // returns the playback position in seconds
Music
instances are heavy, you should usually not have more than one or two at most loaded.
A Music
instance needs to be disposed if it is no longer needed, to free up resources.
music.dispose();
-
Developer's Guide
- Introduction
- Goals & Features
- Community & Support
- Contributing
- Games Built with Libgdx
- Prerequisites
- Gradle Project Setup, Running, Debugging and Packaging
- Project Setup, Running & Debugging
- Third Party Services
- Working from Source
- Using libgdx with other JVM languages
- The Application Framework
- A Simple Game
- File Handling
- Networking
- Preferences
- Input Handling
- Memory Management
- Audio
-
Graphics
- Configuration & Querying Graphics ??
- Fullscreen & VSync
- Continuous & Non-Continuous Rendering
- Clearing the Screen
- Take a Screenshot
- OpenGL ES Support * Configuration & Querying OpenGL ?? * Direct Access ?? * Utility Classes * Rendering Shapes * Textures & TextureRegions * Meshes * Shaders * Frame Buffer Objects
- 2D Graphics * SpriteBatch, TextureRegions, and Sprite * 2D Animation * Clipping, with the use of ScissorStack * Orthographic camera * Mapping Touch Coordinates ?? * Viewports * NinePatches * Bitmap Fonts * Distance field fonts * Using TextureAtlases * Pixmaps * Packing Atlases Offline * Packing Atlases at Runtime * 2D Particle Effects * Tile Maps * scene2d * scene2d.ui * Skin
- 3D Graphics * Quick Start * Models * Material and environment * 3D animations and skinning * Importing Blender models in LibGDX * Perspective Camera ?? * Picking ??
- Managing Your Assets
- Utilities
-
Math Utilities
- Interpolation
- Vectors, Matrices, Quaternions
- Circles, Planes, Rays, etc.
- Path interface & Splines
- Bounding Volumes ??
- Intersection & Overlap Testing ??
- Physics
- Tools
- Extensions
- Deploying your Application
- Building Libgdx ??
- Known Issues
- Articles
- Deprecated (May be outdated)