Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #194 from florinleu/master

[Audio] Android bugfixes.
  • Loading branch information...
commit 081101737963bcbff99e1f1ae5a0055d2398fb73 2 parents 0ea9617 + 3b7739d
Ali Sarrafi authored
View
2  runtimes/cpp/platforms/android/IOCtl.cpp
@@ -4130,7 +4130,7 @@ namespace Base
jmethodID methodID = jNIEnv->GetMethodID(
cls,
- "maAudioSetNUmberOfLoops",
+ "maAudioSetNumberOfLoops",
"(II)I");
if (methodID == 0)
View
81 ...java/platforms/androidJNI/AndroidProject/src/com/mosync/internal/android/MoSyncAudio.java
@@ -268,9 +268,12 @@ boolean isPlaying()
*
* @param playing
*/
- void setPlaying(boolean playing)
+ void setPlaying(boolean playing, boolean looping)
{
- mLoopsLeft = mLooping+1;
+ if (!looping)
+ {
+ mLoopsLeft = mLooping+1;
+ }
mPlaying = playing;
}
@@ -454,7 +457,7 @@ int maAudioDataDestroy(int audioData)
if(null == d)
return -100;
- d.release(mAudioInstance);
+// d.release(mAudioInstance);
/*
String name = d.getFileName();
@@ -470,8 +473,11 @@ int maAudioDataDestroy(int audioData)
{
// if all sounds has been deleted
// it's safe to delete the sound pool.
- mSoundPool.release();
- mSoundPool = null;
+ if (d.getFlags() != MA_AUDIO_DATA_STREAM)
+ {
+ mSoundPool.release();
+ mSoundPool = null;
+ }
}
return MA_AUDIO_ERR_OK;
@@ -559,8 +565,8 @@ int maAudioInstanceDestroy(int audioInstance)
if(instance.isPlaying())
maAudioStop(audioInstance);
- AudioData data = instance.getAudioData();
- data.removeInstance(audioInstance);
+// AudioData data = instance.getAudioData();
+// data.removeInstance(audioInstance);
mAudioInstance.remove(audioInstance);
@@ -604,10 +610,10 @@ int maAudioSetNumberOfLoops(int audio, int loops)
else if(loops == 0)
mMediaPlayer.setLooping(false);
}
- else
- {
- instance.setLooping(loops);
- }
+// else
+// {
+// instance.setLooping(loops);
+// }
return MA_AUDIO_ERR_OK;
}
@@ -619,10 +625,18 @@ int maAudioPrepare(int audio, int async)
AudioInstance instance = getAudioInstance(audio);
if(null == instance)
- return 0;
+ {
+ return MA_AUDIO_ERR_INVALID_INSTANCE;
+ }
if(instance.isPaused())
- return 0;
+ {
+ if (1 == async)
+ {
+ postAudioEvent(EVENT_TYPE_AUDIO_PREPARED, audio);
+ }
+ return MA_AUDIO_ERR_OK;
+ }
AudioData data = instance.getAudioData();
@@ -632,6 +646,10 @@ int maAudioPrepare(int audio, int async)
if(MA_AUDIO_DATA_STREAM != data.getFlags())
{
data.setPreparedState(AUDIO_PREPARED);
+ if (1 == async)
+ {
+ postAudioEvent(EVENT_TYPE_AUDIO_PREPARED, audio);
+ }
return MA_AUDIO_ERR_OK;
}
@@ -714,6 +732,11 @@ boolean prepareMediaPlayer(int audio)
int maAudioPlay(int audio)
{
+ return maAudioPlay(audio, false);
+ }
+
+ int maAudioPlay(int audio, boolean looping)
+ {
AudioInstance instance = getAudioInstance(audio);
if(null == instance)
return MA_AUDIO_ERR_INVALID_INSTANCE;
@@ -781,7 +804,7 @@ int maAudioPlay(int audio)
}
}
- instance.setPlaying(true);
+ instance.setPlaying(true, looping);
return MA_AUDIO_ERR_OK;
}
@@ -923,7 +946,7 @@ int maAudioStop(int audio)
}
}
- instance.setPlaying(false);
+ instance.setPlaying(false, false);
return MA_AUDIO_ERR_OK;
}
@@ -953,19 +976,15 @@ public void onCompletion(MediaPlayer mp)
if(audio.shouldLoop())
{
- if( MA_AUDIO_ERR_OK == maAudioPlay(mActiveStreamingAudio))
- return;
+ if( MA_AUDIO_ERR_OK == maAudioPlay(mActiveStreamingAudio, true))
+ return;
// oops.. we got an error during playback
mActiveStreamingAudio = 0;
}
}
- int[] event = new int[2];
- event[0] = EVENT_TYPE_AUDIO_COMPLETED;
- event[1] = mActiveStreamingAudio;
- mMoSyncThread.postEvent(event);
-
+ postAudioEvent(EVENT_TYPE_AUDIO_COMPLETED, mActiveStreamingAudio);
}
public void onPrepared(MediaPlayer mp)
@@ -978,14 +997,19 @@ public void onPrepared(MediaPlayer mp)
else
mPreparingAudioData = -1;
- int[] event = new int[2];
- event[0] = EVENT_TYPE_AUDIO_PREPARED;
- event[1] = mPreparingAudioData;
- mMoSyncThread.postEvent(event);
+ postAudioEvent(EVENT_TYPE_AUDIO_PREPARED, mPreparingAudioData);
mPreparingAudioData = 0;
}
+ private void postAudioEvent(int type, int data)
+ {
+ int[] event = new int[2];
+ event[0] = type;
+ event[1] = data;
+ mMoSyncThread.postEvent(event);
+ }
+
public boolean onError(MediaPlayer mp, int what, int extra)
{
AudioData audioData = mAudioData.get(mPreparingAudioData);
@@ -993,10 +1017,7 @@ public boolean onError(MediaPlayer mp, int what, int extra)
audioData.setPreparedState(AUDIO_PREPARE_ERROR);
mPreparingAudioData = 0;
- int[] event = new int[2];
- event[0] = EVENT_TYPE_AUDIO_PREPARED;
- event[1] = -1;
- mMoSyncThread.postEvent(event);
+ postAudioEvent(EVENT_TYPE_AUDIO_PREPARED, -1);
return true;
}
Please sign in to comment.
Something went wrong with that request. Please try again.