My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.badlogic.gamedev.samples;

import javax.microedition.khronos.opengles.GL10;

import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.util.Log;

import com.badlogic.gamedev.tools.GameActivity;
import com.badlogic.gamedev.tools.GameListener;

public class SoundSample extends GameActivity implements GameListener
{
int soundId = 0;
SoundPool soundPool;
AudioManager audioManager;
boolean playedSound = false;

public void onCreate( Bundle bundle )
{
super.onCreate(bundle);
setGameListener( this );
}

@Override
public void setup(GameActivity activity, GL10 gl)
{
soundPool = new SoundPool( 5, AudioManager.STREAM_MUSIC, 0);
audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);

try
{
AssetFileDescriptor descriptor = getAssets().openFd( "shot.ogg" );
soundId = soundPool.load( descriptor, 1 );
}
catch( Exception ex )
{
Log.d( "Sound Sample", "couldn't load sound 'shot.ogg'" );
throw new RuntimeException( ex );
}
}

@Override
public void mainLoopIteration(GameActivity activity, GL10 gl)
{
if( activity.isTouched() && playedSound == false )
{
int volume = audioManager.getStreamVolume( AudioManager.STREAM_MUSIC );
soundPool.play(soundId, volume, volume, 1, 0, 1);
playedSound = true;
}

if( !activity.isTouched() )
playedSound = false;
}
}

Change log

r71 by quantumgame on Mar 10, 2011   Diff
[fixed] Ship position
[fixed] SoundSample (wrong file name...)
Go to: 
Project members, sign in to write a code review

Older revisions

r30 by quantumgame on Jan 10, 2010   Diff
[No log message]
All revisions of this file

File info

Size: 1482 bytes, 59 lines
Powered by Google Project Hosting