Author Topic: BASS for Android  (Read 390518 times)

tom128

  • Posts: 9
Re: BASS for Android
« Reply #400 on: 11 Sep '13 - 03:40 »
My current app is using MediaPlayer to play midi file;
  MediaPlayr mPlayer = new MediaPlayer();
  mPlayer.setDataSource(...);
  mPlayer.prepare();
  mPlayer.start();
Pls. advise how to apply soundfont using BASS to my current code. 
I've set soundfont as done in MidiTest and then when I play midi file using BASSMIDI.BASS_MIDI_StreamCreateFile (...) and BASS.BASS_ChannelPlay();
then it works.   But sound does not change when mPlayer.start();

Ian @ un4seen

  • Administrator
  • Posts: 20401
Re: BASS for Android
« Reply #401 on: 11 Sep '13 - 14:42 »
Oh, so you want to use BASS via the MediaPlayer class? I don't think that will be possible. If you would like to use the same calls for BASS and MediaPlayer, then perhaps you could create a little wrapper class for that, eg. the class will use either BASS or MediaPlayer depending on which you want to play the file.

tom128

  • Posts: 9
Re: BASS for Android
« Reply #402 on: 12 Sep '13 - 17:02 »
Then I need to rewrite my code for MediaPlayer class in order for my app to be run on BASS.  My app is for playing midi file and if I find equivalent for MediaPlayer's seekto(..) and onCompletionListener then I can rewrite it.   MediaPlayer's seekto(int msec) take argument integer for miliseconds.(it is time)     Pls. advise which methods could be used for these 2 MediaPlayer's methods.

Ian @ un4seen

  • Administrator
  • Posts: 20401
Re: BASS for Android
« Reply #403 on: 12 Sep '13 - 17:22 »
"seekto(int msec)" would be replaced with BASS_ChannelSeconds2Bytes and BASS_ChannelSetPosition...

Code: [Select]
long bytepos=BASS.BASS_ChannelSeconds2Bytes(handle, msec/1000.0);
result=BASS.BASS_ChannelSetPosition(handle, bytepos, BASS.BASS_POS_BYTE);

"onCompletionListener" would be replaced with a BASS_SYNC_END sync set via BASS_ChannelSetSync...

Code: [Select]
BASS.SYNCPROC EndSync=new BASS.SYNCPROC() {
public void SYNCPROC(int handle, int channel, int data, Object user) {
// do something here
}
};
BASS.BASS_ChannelSetSync(handle, BASS.BASS_SYNC_END, 0, EndSync, 0);

tom128

  • Posts: 9
Re: BASS for Android
« Reply #404 on: 13 Sep '13 - 15:27 »
Thanks a lot !   I'll try it.

Dodge

  • Posts: 32
Re: BASS for Android
« Reply #405 on: 14 Sep '13 - 19:40 »
Hey :)

is it possible to play files with urls like "content://settings/system/alarm_alert" or "content://media/internal/audio/media/127"? :)

i tried with BASS_StreamCreateFile and BASS_StreamCreateURL but both gave me BASS_ERROR_FILEOPEN :(

any info on this question? :)

Ian @ un4seen

  • Administrator
  • Posts: 20401
Re: BASS for Android
« Reply #406 on: 16 Sep '13 - 18:05 »
BASS doesn't support those "content" URLs directly, but you can use the ContentResolver class and BASS_StreamCreateFileUser to play them, eg. use ContentResolver's openInputStream method to open the URL and have the FILEREADPROC callback function read from it. Unfortunately, as far as I can see, seeking isn't possible when opening stuff via the ContentResolver class so you would need to use BASS_StreamCreateFileUser's "buffered" file system, eg. STREAMFILE_BUFFER. It could look something like this...

Code: [Select]
BASS.BASS_FILEPROCS fileprocs=new BASS.BASS_FILEPROCS() {
@Override
public boolean FILESEEKPROC(long offset, Object user) {
// unused in buffered file system
return false;
}

@Override
public int FILEREADPROC(ByteBuffer buffer, int length, Object user) {
InputStream is=(InputStream)user;
byte b[]=new byte[length];
int r=0;
try {
r=is.read(b);
} catch (IOException e) {
}
if (r<=0) return 0;
buffer.put(b, 0, r);
return r;
}

@Override
public long FILELENPROC(Object user) {
return 0;
}

@Override
public void FILECLOSEPROC(Object user) {
InputStream is=(InputStream)user;
try {
is.close();
} catch (IOException e) {
}
}
};

ContentResolver cr=getContentResolver();
try {
InputStream is=cr.openInputStream(url);
stream=BASS.BASS_StreamCreateFileUser(BASS.STREAMFILE_BUFFER, 0, fileprocs, is);
} catch (IOException e) {
}

Another option is to read the entire file into a byte array, and pass that (wrapped in a ByteBuffer) to BASS_StreamCreateFile. I'll see if I can find a better way to do it.

Dodge

  • Posts: 32
Re: BASS for Android
« Reply #407 on: 17 Sep '13 - 07:46 »
Hey Ian,

thank you for your reply.

I'll have a look at this solution as soon as possible.


But after your tip with the ContentResolver i took a look at its api.
could http://developer.android.com/reference/android/content/ContentResolver.html#openAssetFileDescriptor%28android.net.Uri,%20java.lang.String%29 help? iirc there is an option to open assets with BASS?

or this one of ContentProvider http://developer.android.com/reference/android/content/ContentProvider.html#openAssetFile%28android.net.Uri,%20java.lang.String%29


any thoughts?

Ian @ un4seen

  • Administrator
  • Posts: 20401
Re: BASS for Android
« Reply #408 on: 17 Sep '13 - 15:02 »
BASS does include support for assets, but that is only by name, not an AssetFileDescriptor. But it is possible to get a FileChannel from an AssetFileDescriptor, which does permit seeking, so using openAssetFileDescriptor is indeed a better option than using openInputStream as in the code above. The code could be modified like this...

Code: [Select]
BASS.BASS_FILEPROCS fileprocs=new BASS.BASS_FILEPROCS() {
@Override
public boolean FILESEEKPROC(long offset, Object user) {
FileChannel fc=(FileChannel)user;
try {
fc.position(offset);
return true;
} catch (IOException e) {
}
return false;
}

@Override
public int FILEREADPROC(ByteBuffer buffer, int length, Object user) {
FileChannel fc=(FileChannel)user;
try {
return fc.read(buffer);
} catch (IOException e) {
}
return 0;
}

@Override
public long FILELENPROC(Object user) {
FileChannel fc=(FileChannel)user;
try {
return fc.size();
} catch (IOException e) {
}
return 0;
}

@Override
public void FILECLOSEPROC(Object user) {
FileChannel fc=(FileChannel)user;
try {
fc.close();
} catch (IOException e) {
}
}
};

ContentResolver cr=getContentResolver();
try {
AssetFileDescriptor afd=cr.openAssetFileDescriptor(url, "r");
FileChannel fc=afd.createInputStream().getChannel();
stream=BASS.BASS_StreamCreateFileUser(BASS.STREAMFILE_NOBUFFER, 0, fileprocs, fc);
} catch (IOException e) {
}

Another option is to translate the "content://" URL to a filename and then pass that to BASS_StreamCreateFile, something like this...

Code: [Select]
ContentResolver cr=getContentResolver();
Cursor c=cr.query(url, null, null, null, null);
int ci=c.getColumnIndex("_data");
if (ci>=0) {
c.moveToFirst();
String filename=c.getString(ci);
stream=BASS.BASS_StreamCreateFile(filename, 0, 0, 0);
}

Dodge

  • Posts: 32
Re: BASS for Android
« Reply #409 on: 18 Sep '13 - 20:45 »
Got it with your last suggestion using the ContentResolver to get the filenames

Thank you :)


firemen

  • Posts: 151
Re: BASS for Android
« Reply #410 on: 18 Sep '13 - 21:13 »
headers for Delphi5 fmx\android ?

Chris

  • Posts: 1808

firemen

  • Posts: 151
Re: BASS for Android
« Reply #412 on: 21 Sep '13 - 15:30 »
Please, put the minimum working project play mp3 files for Xe5/Android 

ecoldur

  • Posts: 2
Re: BASS for Android
« Reply #413 on: 24 Sep '13 - 21:31 »
Hello;

I am trying to use Bass.Net.Android in my monodroid project

I have included the necessary dll in my project and all the methods are now seen by the compiler and all builds well.

However, any call that I make to any of the methods in the library just hangs the application and never returns from the call

At first I tried to init the Bass by calling this
if (Bass.BASS_Init (-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero))

When the app never returned from the call and just sat there waiting I thought it was the init call causing the problem. After hours of net search to no avail, I decided to place another call before it to see if any other methods would pass, so I coded this

Bass.BASS_GetVersion ();

And the result was the same. Any call that I make to the library just hangs the application. Can I please get some help

Thanks


jhchoi

  • Posts: 14
Re: BASS for Android
« Reply #414 on: 30 Sep '13 - 06:29 »
Hi,
I am using the latest version of BASS for Android (updated: 21 Aug '13) with BASSmix, but it seems that "BASSmix.BASS_Mixer_ChannelSetSync" is not worked correctly.

When I tried a code like this:

Code: [Select]
int chan = BASS.BASS_StreamCreateFile(..., BASS.BASS_STREAM_DECODE);
int mixchan = BASSmix.BASS_Mixer_StreamCreate(44100, 2, BASSmix.BASS_MIXER_NONSTOP);
BASSmix.BASS_Mixer_StreamAddChannel(mixchan, chan, BASSmix.BASS_MIXER_NORAMPIN);
BASSmix.BASS_Mixer_ChannelSetSync(chan, BASS.BASS_SYNC_POS|BASS.BASS_SYNC_ONETIME, (position in bytes), posSyncProc, null);

...

public BASS.SYNCPROC posSyncProc = new BASS.SYNCPROC() {
  public void SYNCPROC(int handle, int channel, int data, Object user) {
    ...
  }
};

when the channel reaches the position I gave, the app crashes with "Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1)". (Tested on Samsung Galaxy S2, Android 4.1.2)
When I use BASS.BASS_ChannelSetSync instead of BASSmix's function, it works well. However, I want to use BASSmix's sync function to consider its delay due to buffering.

Above code with BASS for iOS works well, so I think it is a bug for Android version of BASS. Could you check it?

Ian @ un4seen

  • Administrator
  • Posts: 20401
Re: BASS for Android
« Reply #415 on: 30 Sep '13 - 17:04 »
Oops, BASSmix does indeed have a problem with non-mixtime ONETIME syncs; it's releasing the sync's Java resources before the SYNCPROC function is called. An updated BASSmix version is now up in the 1st post. Let me know if it still gives you any trouble.

tom128

  • Posts: 9
Re: BASS for Android
« Reply #416 on: 1 Oct '13 - 11:24 »
I wonder why BASS for android works in different manner from BASS for windows.   When you install BASS for windows, any program can work on this installed BASS without changing windows program.   But BASS for android does not work like that.   I have to change program if I intend to apply BASS for android application.   Why does it have to work like that ?  is it because any technical barrier exist for android ? or is it because of a strategic decision ? 

jhchoi

  • Posts: 14
Re: BASS for Android
« Reply #417 on: 1 Oct '13 - 12:25 »
Oops, BASSmix does indeed have a problem with non-mixtime ONETIME syncs; it's releasing the sync's Java resources before the SYNCPROC function is called. An updated BASSmix version is now up in the 1st post. Let me know if it still gives you any trouble.

Now it works like a charm! Thanks, Ian!  :D

Ian @ un4seen

  • Administrator
  • Posts: 20401
Re: BASS for Android
« Reply #418 on: 1 Oct '13 - 14:23 »
I wonder why BASS for android works in different manner from BASS for windows.   When you install BASS for windows, any program can work on this installed BASS without changing windows program.   But BASS for android does not work like that.   I have to change program if I intend to apply BASS for android application.   Why does it have to work like that ?  is it because any technical barrier exist for android ? or is it because of a strategic decision ? 

I'm not entirely sure what you mean. Could you please elaborate? Generally, any program that wants to use BASS will need to be modified to do so, eg. by adding some BASS function calls to it.

tom128

  • Posts: 9
Re: BASS for Android
« Reply #419 on: 1 Oct '13 - 16:41 »
I've installed BASS MIDI driver for windows and I've added some soundfonts using BASSMIDI drive configuration then all the program which uses midi seems to make sound using BASS.    E.g. I opened finale notepad then I have choice of using BASS driver so I can hear changed sound from the sound font set by BASS driver.    Do I misunderstand something ?

Ian @ un4seen

  • Administrator
  • Posts: 20401
Re: BASS for Android
« Reply #420 on: 2 Oct '13 - 16:57 »
OK, I see what you mean now: you've installed a BASSMIDI-based driver on Windows, which allows software to play MIDI files via BASSMIDI, and you want to do the same on Android. Unfortunately, I don't think it's possible for users to install drivers on Android. I guess it may be possible for someone to install a BASSMIDI-based driver in a customised firmware.

tom128

  • Posts: 9
Re: BASS for Android
« Reply #421 on: 4 Oct '13 - 20:27 »
To support both arm and x86, what should be done ?  single apk can support both ? Then would you give me some guide about how to prepare for it ?   And I need another help.   I see that reverb you showed in MidiTest is working, which is turning on and off.  Now, how can I control amount(?) of reverb effect.  I appreciate if you show me some example.

Alok

  • Guest
Re: BASS for Android
« Reply #422 on: 6 Oct '13 - 18:18 »
Hi,

I am using bass ( net radio example ) I want to record the live. But the file is not created in my phone. So can you have some example to do so.


Note : I have write permission.but no file is created nor show any error ?

Regards
Alok

Ian @ un4seen

  • Administrator
  • Posts: 20401
Re: BASS for Android
« Reply #423 on: 7 Oct '13 - 12:42 »
A patch for the NETRADIO example to have it write the downloaded data to a file can be found here...

   www.un4seen.com/forum/?topic=13225.msg100319#msg100319

Larry Fine

  • Posts: 16
Re: BASS for Android
« Reply #424 on: 7 Oct '13 - 17:57 »
Sorry if I missed something.

Is there any possibility to implement Musepack SV8 on BASS library for android?

Cheers.