Browse Source

PlayMusic now uses std.filesystem.OpenCFile for streaming.

Mark Sibly 7 years ago
parent
commit
20fdbe75d2

+ 3 - 3
modules/mojo/audio/audio.monkey2

@@ -12,7 +12,7 @@ Namespace mojo.audio
 
 Extern Private
 
-Function playMusic:Int( path:CString,callback:Int,source:Int )="bbMusic::playMusic"
+Function playMusic:Int( file:libc.FILE ptr,callback:Int,source:Int )="bbMusic::playMusic"
 Function getBuffersProcessed:Int( source:Int )="bbMusic::getBuffersProcessed"
 Function endMusic:Void( source:Int )="bbMusic::endMusic"
 	
@@ -72,9 +72,9 @@ Class AudioDevice
 			finished()
 		End,True )
 		
-		path=filesystem.RealPath( path )
+		Local file:=filesystem.OpenCFile( path,"rb" )
 		
-		Local sampleRate:=playMusic( path,callback,channel._alSource )
+		Local sampleRate:=playMusic( file,callback,channel._alSource )
 	
 		If Not sampleRate
 			async.DestroyAsyncCallback( callback )

+ 3 - 51
modules/mojo/audio/native/bbmusic.cpp

@@ -13,9 +13,7 @@
 #include "../../../std/async/native/async_cb.h"
 #include "../../../stb-vorbis/native/stb-vorbis.h"
 
-#if __ANDROID__
-#include "../../../sdl2/SDL/src/core/android/SDL_android.h"
-#endif
+#include <std/filesystem/native/filesystem.h>
 
 #include <atomic>
 
@@ -25,7 +23,7 @@ namespace{
 
 	Counter *counters;
 	
-	//Yikes! We have to make a little atomic counter class!
+	//little atomic counter class...
 	//
 	struct Counter{
 		
@@ -57,59 +55,13 @@ namespace{
 		return 0;
 	}
 }
-	
 
 namespace bbMusic{
 
-#if __ANDROID__
-	
-	int android_read( void *cookie,char *buf,int size ){
-	
-	  return AAsset_read( (AAsset*)cookie,buf,size );
-	}
-	
-	int android_write( void *cookie,const char* buf,int size ){
-	
-	  return EACCES; // can't provide write access to the apk
-	}
-	
-	fpos_t android_seek( void *cookie,fpos_t offset,int whence ){
-	
-	  return AAsset_seek( (AAsset*)cookie,offset,whence );
-	}
-	
-	int android_close(void* cookie) {
-	
-	  AAsset_close( (AAsset*)cookie );
-	  return 0;
-	}
-	
-#endif
-	
-	FILE *fopen( const char *path,const char *mode ){
-	
-#if __ANDROID__
-		if( !strncmp( path,"asset::",7 ) ){
-			
-			AAssetManager *assetManager=Android_JNI_GetAssetManager();
-			if( !assetManager ) return 0;
-			
-	  		AAsset* asset=AAssetManager_open( assetManager,path+7,0 );
-			if( !asset ) return 0;
-	
-	  		return funopen( asset,android_read,android_write,android_seek,android_close );
-		}
-#endif
-		return ::fopen( path,mode );
-	}
-
-	int playMusic( const char *path,int callback,int alsource ){
+	int playMusic( FILE *file,int callback,int alsource ){
 	
 		const int buffer_ms=100;
 			
-		FILE *file=fopen( path,"rb" );
-		if( !file ) return false;
-	
 		int error=0;
 		stb_vorbis *vorbis=stb_vorbis_open_file( file,0,&error,0 );
 		if( !vorbis ) return false;

+ 3 - 1
modules/mojo/audio/native/bbmusic.h

@@ -1,7 +1,9 @@
 
+#include <std/filesystem/native/filesystem.h>
+
 namespace bbMusic{
 
-	int playMusic( const char *path,int callback,int source );
+	int playMusic( FILE *file,int callback,int source );
 	
 	int getBuffersProcessed( int source );