Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #194 from florinleu/master

[Audio] Android bugfixes.
  • Loading branch information...
commit 081101737963bcbff99e1f1ae5a0055d2398fb73 2 parents 0ea9617 + 3b7739d
authored June 25, 2012
2  runtimes/cpp/platforms/android/IOCtl.cpp
@@ -4130,7 +4130,7 @@ namespace Base
4130 4130
 
4131 4131
 		jmethodID methodID = jNIEnv->GetMethodID(
4132 4132
 			cls,
4133  
-			"maAudioSetNUmberOfLoops",
  4133
+			"maAudioSetNumberOfLoops",
4134 4134
 			"(II)I");
4135 4135
 
4136 4136
 		if (methodID == 0)
81  runtimes/java/platforms/androidJNI/AndroidProject/src/com/mosync/internal/android/MoSyncAudio.java
@@ -268,9 +268,12 @@ boolean isPlaying()
268 268
 		 *
269 269
 		 * @param playing
270 270
 		 */
271  
-		void setPlaying(boolean playing)
  271
+		void setPlaying(boolean playing, boolean looping)
272 272
 		{
273  
-			mLoopsLeft = mLooping+1;
  273
+			if (!looping)
  274
+			{
  275
+				mLoopsLeft = mLooping+1;
  276
+			}
274 277
 			mPlaying = playing;
275 278
 		}
276 279
 
@@ -454,7 +457,7 @@ int maAudioDataDestroy(int audioData)
454 457
 		if(null == d)
455 458
 			return -100;
456 459
 
457  
-		d.release(mAudioInstance);
  460
+//		d.release(mAudioInstance);
458 461
 
459 462
 /*
460 463
 		String name = d.getFileName();
@@ -470,8 +473,11 @@ int maAudioDataDestroy(int audioData)
470 473
 		{
471 474
 			// if all sounds has been deleted
472 475
 			// it's safe to delete the sound pool.
473  
-			mSoundPool.release();
474  
-			mSoundPool = null;
  476
+			if (d.getFlags() != MA_AUDIO_DATA_STREAM)
  477
+			{
  478
+				mSoundPool.release();
  479
+				mSoundPool = null;
  480
+			}
475 481
 		}
476 482
 
477 483
 		return MA_AUDIO_ERR_OK;
@@ -559,8 +565,8 @@ int maAudioInstanceDestroy(int audioInstance)
559 565
 		if(instance.isPlaying())
560 566
 			maAudioStop(audioInstance);
561 567
 
562  
-		AudioData data = instance.getAudioData();
563  
-		data.removeInstance(audioInstance);
  568
+//		AudioData data = instance.getAudioData();
  569
+//		data.removeInstance(audioInstance);
564 570
 
565 571
 		mAudioInstance.remove(audioInstance);
566 572
 
@@ -604,10 +610,10 @@ int maAudioSetNumberOfLoops(int audio, int loops)
604 610
 			else if(loops == 0)
605 611
 				mMediaPlayer.setLooping(false);
606 612
 		}
607  
-		else
608  
-		{
609  
-			instance.setLooping(loops);
610  
-		}
  613
+//		else
  614
+//		{
  615
+//			instance.setLooping(loops);
  616
+//		}
611 617
 
612 618
 		return MA_AUDIO_ERR_OK;
613 619
 	}
@@ -619,10 +625,18 @@ int maAudioPrepare(int audio, int async)
619 625
 
620 626
 		AudioInstance instance = getAudioInstance(audio);
621 627
 		if(null == instance)
622  
-			return 0;
  628
+		{
  629
+			return MA_AUDIO_ERR_INVALID_INSTANCE;
  630
+		}
623 631
 
624 632
 		if(instance.isPaused())
625  
-			return 0;
  633
+		{
  634
+			if (1 == async)
  635
+			{
  636
+				postAudioEvent(EVENT_TYPE_AUDIO_PREPARED, audio);
  637
+			}
  638
+			return MA_AUDIO_ERR_OK;
  639
+		}
626 640
 
627 641
 		AudioData data = instance.getAudioData();
628 642
 
@@ -632,6 +646,10 @@ int maAudioPrepare(int audio, int async)
632 646
 		if(MA_AUDIO_DATA_STREAM != data.getFlags())
633 647
 		{
634 648
 			data.setPreparedState(AUDIO_PREPARED);
  649
+			if (1 == async)
  650
+			{
  651
+				postAudioEvent(EVENT_TYPE_AUDIO_PREPARED, audio);
  652
+			}
635 653
 			return MA_AUDIO_ERR_OK;
636 654
 		}
637 655
 
@@ -714,6 +732,11 @@ boolean prepareMediaPlayer(int audio)
714 732
 
715 733
 	int maAudioPlay(int audio)
716 734
 	{
  735
+		return maAudioPlay(audio, false);
  736
+	}
  737
+
  738
+	int maAudioPlay(int audio, boolean looping)
  739
+	{
717 740
 		AudioInstance instance = getAudioInstance(audio);
718 741
 		if(null == instance)
719 742
 			return MA_AUDIO_ERR_INVALID_INSTANCE;
@@ -781,7 +804,7 @@ int maAudioPlay(int audio)
781 804
 			}
782 805
 		}
783 806
 
784  
-		instance.setPlaying(true);
  807
+		instance.setPlaying(true, looping);
785 808
 
786 809
 		return MA_AUDIO_ERR_OK;
787 810
 	}
@@ -923,7 +946,7 @@ int maAudioStop(int audio)
923 946
 			}
924 947
 		}
925 948
 
926  
-		instance.setPlaying(false);
  949
+		instance.setPlaying(false, false);
927 950
 
928 951
 		return MA_AUDIO_ERR_OK;
929 952
 	}
@@ -953,19 +976,15 @@ public void onCompletion(MediaPlayer mp)
953 976
 
954 977
 			if(audio.shouldLoop())
955 978
 			{
956  
-				if( MA_AUDIO_ERR_OK == maAudioPlay(mActiveStreamingAudio))
957  
-				return;
  979
+				if( MA_AUDIO_ERR_OK == maAudioPlay(mActiveStreamingAudio, true))
  980
+					return;
958 981
 
959 982
 				// oops.. we got an error during playback
960 983
 				mActiveStreamingAudio = 0;
961 984
 			}
962 985
 		}
963 986
 
964  
-		int[] event = new int[2];
965  
-		event[0] = EVENT_TYPE_AUDIO_COMPLETED;
966  
-		event[1] = mActiveStreamingAudio;
967  
-		mMoSyncThread.postEvent(event);
968  
-
  987
+		postAudioEvent(EVENT_TYPE_AUDIO_COMPLETED, mActiveStreamingAudio);
969 988
 	}
970 989
 
971 990
 	public void onPrepared(MediaPlayer mp)
@@ -978,14 +997,19 @@ public void onPrepared(MediaPlayer mp)
978 997
 		else
979 998
 			mPreparingAudioData = -1;
980 999
 
981  
-		int[] event = new int[2];
982  
-		event[0] = EVENT_TYPE_AUDIO_PREPARED;
983  
-		event[1] = mPreparingAudioData;
984  
-		mMoSyncThread.postEvent(event);
  1000
+		postAudioEvent(EVENT_TYPE_AUDIO_PREPARED, mPreparingAudioData);
985 1001
 
986 1002
 		mPreparingAudioData = 0;
987 1003
 	}
988 1004
 
  1005
+	private void postAudioEvent(int type, int data)
  1006
+	{
  1007
+		int[] event = new int[2];
  1008
+		event[0] = type;
  1009
+		event[1] = data;
  1010
+		mMoSyncThread.postEvent(event);
  1011
+	}
  1012
+
989 1013
 	public boolean onError(MediaPlayer mp, int what, int extra)
990 1014
 	{
991 1015
 		AudioData audioData = mAudioData.get(mPreparingAudioData);
@@ -993,10 +1017,7 @@ public boolean onError(MediaPlayer mp, int what, int extra)
993 1017
 		audioData.setPreparedState(AUDIO_PREPARE_ERROR);
994 1018
 		mPreparingAudioData = 0;
995 1019
 
996  
-		int[] event = new int[2];
997  
-		event[0] = EVENT_TYPE_AUDIO_PREPARED;
998  
-		event[1] = -1;
999  
-		mMoSyncThread.postEvent(event);
  1020
+		postAudioEvent(EVENT_TYPE_AUDIO_PREPARED, -1);
1000 1021
 
1001 1022
 		return true;
1002 1023
 	}

0 notes on commit 0811017

Please sign in to comment.
Something went wrong with that request. Please try again.