Skip to content

Commit 8ae38ee

Browse files
committed
Merge branch 'master' of github.com:haxenme/NME
git-svn-id: https://nekonme.googlecode.com/svn/trunk@2172 1509560c-5e2a-0410-865c-31c25e1cfdef
2 parents e32ce87 + c7db445 commit 8ae38ee

File tree

5 files changed

+130
-95
lines changed

5 files changed

+130
-95
lines changed

neash/media/SoundChannel.hx

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,28 @@ class SoundChannel extends EventDispatcher
5656
{
5757
if (nmeHandle != null )
5858
{
59-
if (nmeDataProvider!=null && nme_sound_channel_needs_data(nmeHandle))
60-
{
61-
var request = new SampleDataEvent(SampleDataEvent.SAMPLE_DATA);
62-
request.position = nme_sound_channel_get_data_position(nmeHandle);
63-
nmeDataProvider.dispatchEvent(request);
64-
if (request.data.length > 0)
65-
nme_sound_channel_add_data(nmeHandle,request.data);
66-
}
59+
if (nmeDataProvider!=null && nme_sound_channel_needs_data(nmeHandle))
60+
{
61+
var request = new SampleDataEvent(SampleDataEvent.SAMPLE_DATA);
62+
request.position = nme_sound_channel_get_data_position(nmeHandle);
63+
nmeDataProvider.dispatchEvent(request);
64+
if (request.data.length > 0) {
65+
nme_sound_channel_add_data(nmeHandle,request.data);
66+
}
67+
}
6768

68-
if (nme_sound_channel_is_complete(nmeHandle))
69-
{
70-
nmeHandle = null;
71-
if (nmeDataProvider!=null)
72-
nmeDynamicSoundCount--;
73-
var complete = new Event(Event.SOUND_COMPLETE);
74-
dispatchEvent(complete);
75-
return true;
76-
}
69+
if (nme_sound_channel_is_complete(nmeHandle))
70+
{
71+
nmeHandle = null;
72+
if (nmeDataProvider!=null) {
73+
nmeDynamicSoundCount--;
74+
}
75+
var complete = new Event(Event.SOUND_COMPLETE);
76+
dispatchEvent(complete);
77+
return true;
78+
}
7779
}
78-
80+
7981
return false;
8082
}
8183

@@ -108,6 +110,7 @@ class SoundChannel extends EventDispatcher
108110
public function stop()
109111
{
110112
nme_sound_channel_stop(nmeHandle);
113+
nmeHandle = null;
111114
}
112115

113116

project/android/AndroidSound.cpp

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <Sound.h>
22
#include <Display.h>
3+
#include <Utils.h>
34
#include <jni.h>
45

56
#include <android/log.h>
@@ -23,15 +24,15 @@ namespace nme
2324
JNIEnv *env = GetEnv();
2425
mStreamID = -1;
2526
mSound = inSound;
27+
mSoundHandle = inHandle;
28+
mLoop = (loops < 1) ? 1 : loops;
2629
inSound->IncRef();
27-
if (inHandle>=0)
30+
if (inHandle >= 0)
2831
{
2932
jclass cls = env->FindClass("org/haxe/nme/Sound");
3033
jmethodID mid = env->GetStaticMethodID(cls, "playSound", "(IDDI)I");
31-
if (mid > 0)
32-
{
33-
// LOGV("Android Sound Channel found play method");
34-
mStreamID = env->CallStaticIntMethod(cls, mid, inHandle, inTransform.volume*((1-inTransform.pan)/2), inTransform.volume*((inTransform.pan+1)/2), loops );
34+
if (mid > 0) {
35+
mStreamID = env->CallStaticIntMethod(cls, mid, inHandle, inTransform.volume*((1-inTransform.pan)/2), inTransform.volume*((inTransform.pan+1)/2), mLoop );
3536
}
3637
}
3738
}
@@ -43,7 +44,12 @@ namespace nme
4344

4445
bool isComplete()
4546
{
46-
return true;
47+
JNIEnv *env = GetEnv();
48+
jclass cls = env->FindClass("org/haxe/nme/Sound");
49+
jmethodID mid = env->GetStaticMethodID(cls, "getSoundComplete", "(III)Z");
50+
if (mid > 0) {
51+
return env->CallStaticIntMethod(cls, mid, mSoundHandle, mStreamID, mLoop);
52+
}
4753
}
4854

4955
double getLeft()
@@ -58,6 +64,12 @@ namespace nme
5864

5965
double getPosition()
6066
{
67+
JNIEnv *env = GetEnv();
68+
jclass cls = env->FindClass("org/haxe/nme/Sound");
69+
jmethodID mid = env->GetStaticMethodID(cls, "getSoundPosition", "(II)I");
70+
if (mid > 0) {
71+
return env->CallStaticIntMethod(cls, mid, mSoundHandle, mStreamID, mLoop);
72+
}
6173
}
6274

6375
void stop()
@@ -79,6 +91,8 @@ namespace nme
7991

8092
Object *mSound;
8193
int mStreamID;
94+
int mSoundHandle;
95+
int mLoop;
8296
};
8397

8498
SoundChannel *SoundChannel::Create(const ByteArray &inBytes,const SoundTransform &inTransform)
@@ -207,7 +221,6 @@ namespace nme
207221
mMode = MODE_UNKNOWN;
208222
handleID = -1;
209223
mLength = 0;
210-
mManagerID = getSoundPoolID();
211224
mSoundPath = inPath;
212225

213226
jclass cls = env->FindClass("org/haxe/nme/Sound");
@@ -282,29 +295,11 @@ namespace nme
282295

283296
void close() { }
284297

285-
int getSoundPoolID()
286-
{
287-
JNIEnv *env = GetEnv();
288-
jclass cls = env->FindClass("org/haxe/nme/Sound");
289-
jmethodID mid = env->GetStaticMethodID(cls, "getSoundPoolID", "()I");
290-
if (mid > 0) {
291-
return env->CallStaticIntMethod(cls, mid);
292-
}
293-
return 0;
294-
}
295-
296298
SoundChannel *openChannel(double startTime, int loops, const SoundTransform &inTransform)
297299
{
298300
switch (mMode) {
299301
case MODE_SOUND_ID:
300-
{
301-
int mid = getSoundPoolID();
302-
if (mid != mManagerID) {
303-
mManagerID = mid;
304-
reloadSound();
305-
}
306-
return new AndroidSoundChannel(this, handleID, startTime, loops, inTransform);
307-
}
302+
return new AndroidSoundChannel(this, handleID, startTime, loops, inTransform);
308303
break;
309304
case MODE_MUSIC_PATH:
310305
default:
@@ -315,7 +310,7 @@ namespace nme
315310

316311
int handleID;
317312
int mLength;
318-
int mManagerID;
313+
// int mManagerID;
319314
std::string mSoundPath;
320315
SoundMode mMode;
321316
};

samples/19-AndroidJNI/gen/org/haxe/nme/GameActivity.hx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,6 @@ class GameActivity extends android.app.Activity
4343
return nme.JNI.callStatic(_getMusicHandle_func,[arg0]);
4444
}
4545

46-
static var _getSoundPoolID_func:Dynamic;
47-
public static function getSoundPoolID() : Dynamic
48-
{
49-
if (_getSoundPoolID_func==null)
50-
_getSoundPoolID_func=nme.JNI.createStaticMethod("org.haxe.nme.Sound","getSoundPoolID","()I");
51-
return nme.JNI.callStatic(_getSoundPoolID_func,[]);
52-
}
53-
5446
static var _getContext_func:Dynamic;
5547
public static function getContext() : Dynamic
5648
{

templates/default/android/template/src/org/haxe/nme/MainView.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ private static class Renderer implements GLSurfaceView.Renderer {
356356
public void onDrawFrame(GL10 gl) {
357357
//Log.v("VIEW","onDrawFrame !");
358358
mMainView.HandleResult( NME.onRender() );
359+
Sound.checkSoundCompletion();
359360
//Log.v("VIEW","onDrawFrame DONE!");
360361
}
361362

0 commit comments

Comments
 (0)