audio

module audio

Android audio services, wraps a part of android audio API

This module modifies the default behaviour of the audio loading: It is first loaded from the res/raw folder. The file extension is not needed for the res/raw loading part. If it didn't work, it is loaded from the assets folder. The file extension is needed for the assets loading part.

assets contains the portable version of sounds, since the res folder exsists only in android projects.

For this example, the sounds "test_sound" and "test_music" are located in the "assets/sounds" folder, they both have ".ogg" extension. "test_sound" is a short sound and "test_music" a music track

var s = app.load_sound("sounds/test_sound.ogg")
var m = app.load_music("sounds/test_music.ogg")
s.play
m.play

Now, the sounds are in "res/raw"

s = app.load_sound_from_res("test_sound")
m = app.load_music_from_res("test_sound")
s.play
m.play

See http://developer.android.com/reference/android/media/package-summary.html for more infos

Dependencies

Imports

  • assets_and_resources: Android Assets and Resources Management
  • audio: Services to load and play Sound and Music from the assets folder

Concerns

  • android: Android platform support and APIs
    • audio: Android audio services, wraps a part of android audio API
  • app: app.nit, a framework for portable applications
    • app_base: Base of the app.nit framework, defines App
    • audio: Services to load and play Sound and Music from the assets folder

in android::audio

MediaPlayer

class MediaPlayer

Used to play sounds, designed to use with medium sized sounds or streams

The Android MediaPlayer has a complex state diagram that you'll need to respect if you want your MediaPlayer to work fine, see the android doc

Introduces
  • is_prepared=: Used to control the state of the mediaplayer
  • sound: The sound associated with this mediaplayer
  • sound=: The sound associated with this mediaplayer
  • error: Error gestion
  • error=: Error gestion
  • from_id: Init the mediaplayer with a sound resource id
  • load_sound: Load a sound for a given resource id
  • start: Starts or resumes playback
  • stop: Stops playback after playback has been stopped or paused
  • prepare: Prepares the player for playback, synchronously
  • pause: Pauses playback
  • playing: Checks whether the mediaplayer is playing
  • destroy: Releases the resources associated with this MediaPlayer
  • reset: Reset MediaPlayer to its initial state
  • data_source: Sets the datasource (file-path or http/rtsp URL) to use
  • data_source_fd: Sets the data source (NativeFileDescriptor) to use
  • looping: Checks whether the MediaPlayer is looping or non-looping
  • looping=: Sets the player to be looping or non-looping
  • volume=: Sets the volume on this player
  • both_volume: Sets the left volume and the right volume of this player
  • stream_type=: Sets the audio stream type for this media player
Redefines
  • SELF: Type of this instance, automatically specialized in every class
  • init: Create a new MediaPlayer, but no sound is attached, you'll need

SoundPool

class SoundPool

Used to play sound, best suited for sounds effects in apps or games

Introduces
  • error: Latest error on this sound pool
  • error=: Latest error on this sound pool
  • max_streams: The maximum number of simultaneous streams for this SoundPool
  • max_streams=: The maximum number of simultaneous streams for this SoundPool
  • stream_type: The audio stream type, 3 is STREAM_MUSIC, default for game application
  • stream_type=: The audio stream type, 3 is STREAM_MUSIC, default for game application
  • src_quality: The sample-rate converter quality, currently has no effect
  • src_quality=: The sample-rate converter quality, currently has no effect
  • left_volume: Left volume value, range 0.0 to 1.0
  • left_volume=: Left volume value, range 0.0 to 1.0
  • right_volume: Right volume value, range 0.0 to 1.0
  • right_volume=: Right volume value, range 0.0 to 1.0
  • rate: Playback rate, 1.0 = normal playback, range 0.5 to 2.0
  • rate=: Playback rate, 1.0 = normal playback, range 0.5 to 2.0
  • looping: Loop mode, 0 = no loop, -1 = loop forever
  • looping=: Loop mode, 0 = no loop, -1 = loop forever
  • load_id: Load the sound from its resource id
  • load_path: Load the sound from the specified path
  • play: Play a sound from a sound ID
  • load_name: Load a sound by its name in the resources, the sound must be in the res/raw folder
  • pause_stream: Pause a playback stream
  • auto_pause: Pause all active_streams
  • auto_resume: Resume all previously active streams
  • resume: Resume a playback stream
  • stream_loop=: Set loop mode on a stream
  • stream_priority=: Change stream priority
  • stream_rate=: Change playback rate
  • stream_volume: Set stream volume
  • stop_stream: Stop a playback stream
  • unload: Unload a sound from a sound ID
  • destroy: Destroys the object
Redefines
  • SELF: Type of this instance, automatically specialized in every class
  • init

from app::app_base

App

app::App

redef class App

App subclasses are cross-platform applications

This class is refined by platform modules and so App can be specialized directly in the user application code.

Redefines
  • on_pause: The application leaves the active state but is still partially visible
  • on_create: The application is being created
  • on_resume: The application enters the active state, it is in the foreground and interactive

from app::audio

Music

PlayableAudio

Sound