Browse Source

Fixed a couple issues with the streaming audio player class

Tim Newell 12 years ago
parent
commit
45634343cb

+ 1 - 1
engine/compilers/android/AndroidManifest.xml

@@ -10,7 +10,7 @@
 
 
     <uses-sdk
     <uses-sdk
         android:minSdkVersion="9"
         android:minSdkVersion="9"
-        android:targetSdkVersion="15" />   
+        android:targetSdkVersion="18" />   
     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
     <uses-feature android:glEsVersion="0x00010001" />
     <uses-feature android:glEsVersion="0x00010001" />

+ 6 - 1
engine/compilers/android/src/com/garagegames/torque2d/StreamingAudioPlayer.java

@@ -5,6 +5,7 @@ import java.io.IOException;
 import android.content.Context;
 import android.content.Context;
 import android.content.res.AssetFileDescriptor;
 import android.content.res.AssetFileDescriptor;
 import android.media.MediaPlayer;
 import android.media.MediaPlayer;
+import android.util.Log;
 
 
 public class StreamingAudioPlayer {
 public class StreamingAudioPlayer {
 	
 	
@@ -16,7 +17,11 @@ public class StreamingAudioPlayer {
 		AssetFileDescriptor fd;
 		AssetFileDescriptor fd;
 		try {
 		try {
 			fd = context.getAssets().openFd(filename);
 			fd = context.getAssets().openFd(filename);
-			mediaPlayer.setDataSource(fd.getFileDescriptor());
+			if (fd == null)
+				Log.i("torque2d", "failed to load music file " + filename);
+			
+			mediaPlayer.setDataSource(fd.getFileDescriptor(),fd.getStartOffset(),fd.getLength());
+			mediaPlayer.prepare();
 		} catch (IOException e) {
 		} catch (IOException e) {
 			// TODO Auto-generated catch block
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 			e.printStackTrace();

+ 10 - 8
engine/source/platformAndroid/AndroidStreamSource.cc

@@ -34,8 +34,6 @@ AndroidStreamSource::AndroidStreamSource(const char *filename)  {
 	int len = dStrlen( filename );
 	int len = dStrlen( filename );
 	mFilename = new char[len + 1];
 	mFilename = new char[len + 1];
 	dStrcpy( mFilename, filename );
 	dStrcpy( mFilename, filename );
-
-	android_LoadMusicTrack( mFilename );
 }
 }
 
 
 AndroidStreamSource::~AndroidStreamSource() {
 AndroidStreamSource::~AndroidStreamSource() {
@@ -50,14 +48,9 @@ bool AndroidStreamSource::isPlaying() {
 
 
 bool AndroidStreamSource::start( bool loop ) {
 bool AndroidStreamSource::start( bool loop ) {
 
 
+	Con::printf("Starting music file: %s", mFilename);
 	android_LoadMusicTrack( mFilename );
 	android_LoadMusicTrack( mFilename );
 	android_StartMusicTrack();
 	android_StartMusicTrack();
-	if( !loop ) {
-		//stop at end
-		android_StopMusicTrack();
-		Con::executef(1,"onAndroidStreamEnd");
-	}
-
 	return true;
 	return true;
 }
 }
 
 
@@ -75,3 +68,12 @@ bool AndroidStreamSource::setVolume( F32 volume) {
 
 
     return true;
     return true;
 }
 }
+AndroidStreamSource* stream = NULL;
+ConsoleFunction(playStreamingMusic, void, 2, 2, "")
+{
+	if (stream != NULL)
+		delete stream;
+
+	stream = new AndroidStreamSource(argv[1]);
+	stream->start();
+}