Author Topic: BASS for Android  (Read 445054 times)

mcooper

  • Posts: 53
Re: BASS for Android
« Reply #1450 on: 10 Sep '18 - 09:41 »
The BASS_STREAM_RESTRATE flag doesn't have any effect during stream creation (it only limits the download rate afterwards), so it was probably just coincidence if you did notice a difference.

Please also give the numerical "ctype" values, just to be sure.

Thank you.  I think I've noticed two separate issues, one of which might only be occuring in my simple test app.  I'll add some more logging to the original app to double check the stream handle after creation and the ctype.  I'll also try to repro the error in the test app again.

mcooper

  • Posts: 53
Re: BASS for Android
« Reply #1451 on: 11 Sep '18 - 11:41 »
In both success and failure case, a non-zero stream handle is returned form BASS_StreamCreateURL and BASS_ChannelGetInfo returns a value of 68353 ( MP4, 44100Hz, Stereo, 16bit).  I can then call BASS_ChannelPlay which returns true and BASS_Start also returns true.  BASS_ErrorGetCode returns BASS_OK.  No audio output is heard though.
« Last Edit: 11 Sep '18 - 11:53 by mcooper »

Ian @ un4seen

  • Administrator
  • Posts: 21211
Re: BASS for Android
« Reply #1452 on: 11 Sep '18 - 13:53 »
OK. If you monitor the BASS_ChannelGetPosition and BASS_ChannelGetLevel return values (eg. in a timer), do they show the playback position advancing and the stream having sound?

From the "ctype" value, it looks like you're currently using the BASS_AAC add-on. For comparison, what happens if you try to play the file without the BASS_AAC add-on?

mcooper

  • Posts: 53
Re: BASS for Android
« Reply #1453 on: 11 Sep '18 - 16:39 »
BASS_ChannelGetPosition is used, and it doesn't show the playback position advancing. 

I'll try adding BASS_ChannelGetLevel to see if that returns anything.

I've tested again with and without BASS_STREAM_RESTRATE and it definitely makes a difference.  When I remove it, I can't repro the issue.  When I add it back in, the problem returns.  I've also noticed the the tracks that fail to play are usually longer tracks / bigger media files.

Bass_AAC plugin is used.  I think the files don't play without it, but I can retest.

mcooper

  • Posts: 53
Re: BASS for Android
« Reply #1454 on: 12 Sep '18 - 11:25 »
BASS_ChannelGetPosition is used, and it doesn't show the playback position advancing. 

I'll try adding BASS_ChannelGetLevel to see if that returns anything.

I've tested again with and without BASS_STREAM_RESTRATE and it definitely makes a difference.  When I remove it, I can't repro the issue.  When I add it back in, the problem returns.  I've also noticed the the tracks that fail to play are usually longer tracks / bigger media files.

Bass_AAC plugin is used.  I think the files don't play without it, but I can retest.

I've also added in BASS_ChannelGetLevel which returns 0 in the failure case (and a value for streams that play).

Without the Bass_AAC plugin, BASS_StreamCreateURL returns 0 with an error of BASS_ERROR_HANDLE.

I'm rebuilding the app without BASS_STREAM_RESTRATE and extra logging.  I think the removal of that flag solves most or all of the errors.



Ian @ un4seen

  • Administrator
  • Posts: 21211
Re: BASS for Android
« Reply #1455 on: 12 Sep '18 - 17:39 »
BASS_ChannelGetPosition is used, and it doesn't show the playback position advancing. 

OK. That sounds like the stream stops early rather than playing silence. What position is it stopping at, and what does BASS_ChannelIsActive say then? Also check what BASS_StreamGetFilePosition with BASS_FILEPOS_CONNECTED says.

BASS_STREAM_RESTRATE will limit the download rate after the stream has been created, so as the problem is happening after the stream has created then it is possible that it is having some bearing. Of course, it shouldn't result in the stream ending early, so that is something that will need to be fixed in BASS_AAC if it is. The effect of BASS_STREAM_RESTRATE is determined by the BASS_CONFIG_NET_BUFFER setting and the file's bitrate. What BASS_CONFIG_NET_BUFFER setting are you using, and does increasing that prevent the problem happening?

mcooper

  • Posts: 53
Re: BASS for Android
« Reply #1456 on: 14 Sep '18 - 15:28 »
BASS_ChannelGetPosition is used, and it doesn't show the playback position advancing. 

OK. That sounds like the stream stops early rather than playing silence. What position is it stopping at, and what does BASS_ChannelIsActive say then? Also check what BASS_StreamGetFilePosition with BASS_FILEPOS_CONNECTED says.

BASS_STREAM_RESTRATE will limit the download rate after the stream has been created, so as the problem is happening after the stream has created then it is possible that it is having some bearing. Of course, it shouldn't result in the stream ending early, so that is something that will need to be fixed in BASS_AAC if it is. The effect of BASS_STREAM_RESTRATE is determined by the BASS_CONFIG_NET_BUFFER setting and the file's bitrate. What BASS_CONFIG_NET_BUFFER setting are you using, and does increasing that prevent the problem happening?

The playback doesn't start at all - position remains at 0.

BASS_StreamGetFilePosition returns 1 and BASS_ChannelIsActive returns BASS_ACTIVE_STALLED.

BASS_CONFIG_NET_BUFFER was left as the default value (5s?).  I've tried increasing to 30s and I've not been able to repro the problem with that value yet.  I'll keep testing and try some smaller values too.


Ian @ un4seen

  • Administrator
  • Posts: 21211
Re: BASS for Android
« Reply #1457 on: 14 Sep '18 - 16:18 »
BASS_StreamGetFilePosition returns 1 and BASS_ChannelIsActive returns BASS_ACTIVE_STALLED.

That indicates that playback was stalled by BASS because the decoder (BASS_AAC) isn't providing any data to play. I suspect that is happening because the decoder needs data from a later position in the file and it's waiting for the download to reach there, but that is happening very slowly due to BASS_STREAM_RESTRATE being enabled. Here's an update for you to try, which should temporarily disable BASS_STREAM_RESTRATE in that situation:

   www.un4seen.com/stuff/bass_aac-android.zip

Let me know if you still get the problem happening with that.

mcooper

  • Posts: 53
Re: BASS for Android
« Reply #1458 on: 17 Sep '18 - 11:04 »
BASS_StreamGetFilePosition returns 1 and BASS_ChannelIsActive returns BASS_ACTIVE_STALLED.

That indicates that playback was stalled by BASS because the decoder (BASS_AAC) isn't providing any data to play. I suspect that is happening because the decoder needs data from a later position in the file and it's waiting for the download to reach there, but that is happening very slowly due to BASS_STREAM_RESTRATE being enabled. Here's an update for you to try, which should temporarily disable BASS_STREAM_RESTRATE in that situation:

   www.un4seen.com/stuff/bass_aac-android.zip

Let me know if you still get the problem happening with that.

That does seem to fix the issue.  I've added back the BASS_STREAM_RESTRATE flag and have left BASS_CONFIG_NET_BUFFER as the default, and I've not yet been able to repro the issue.

Ian @ un4seen

  • Administrator
  • Posts: 21211
Re: BASS for Android
« Reply #1459 on: 17 Sep '18 - 13:48 »
That's great. I can't think of any other currently supported file formats (besides MP4) that might have this issue, but it would probably be best to have BASS handle the temporary BASS_STREAM_RESTRATE disabling anyway, just in case. So here's a BASS update for you to try:

   www.un4seen.com/stuff/bass-android-test.zip

Please see if you can reproduce the problem with that and the previous BASS_AAC version. If you don't still have the previous BASS_AAC version, I've put it back up here:

   www.un4seen.com/stuff/bass_aac-android.zip

mcooper

  • Posts: 53
Re: BASS for Android
« Reply #1460 on: 17 Sep '18 - 14:55 »
That also seems to solve the problem.  Thank you
« Last Edit: 17 Sep '18 - 15:31 by mcooper »

mcooper

  • Posts: 53
Re: BASS for Android
« Reply #1461 on: 10 Oct '18 - 16:07 »
Hello Ian,

We are having another issue preventing playback from working when the android app is in the background.  If we play a track (in the foreground) and then background the app - the next track fails to load.  We think this is related to Android Doze mode (https://developer.android.com/training/monitoring-device-state/doze-standby).  Some devices seem unaffected by this, but by forcing doze mode (adb shell dumpsys deviceidle force-idle) the issue is seems to be reproducible on any device.  We didn't notice this issue before, so it appears to have only started after we included bass_ssl, which we think we require as ssl streams fail on some devices without it.

So, we think that bass_sll doesn't cope with android doze mode.  Is that possible, or do you have any suggestions that we can use to try to debug further?

Thanks,

Matt

Ian @ un4seen

  • Administrator
  • Posts: 21211
Re: BASS for Android
« Reply #1462 on: 10 Oct '18 - 17:40 »
According to the Android documentation, Doze does suspend network access, so BASS_SSL could be affected that way but I would expect the problem to happen without BASS_SSL too, ie. not BASS_SSL specifically. Does the problem not happen when you play a HTTP URL instead of a HTTPS one?

Does your app implement a foreground service? And does whitelisting the app in Android's "Battery optimization" settings page make a difference? I believe either of those things should prevent the app being affected.

mcooper

  • Posts: 53
Re: BASS for Android
« Reply #1463 on: 12 Oct '18 - 10:02 »
Thank you for the suggestion.  Actually the problem did happen with http urls too, so it's not related to bass_sll.

Yes, the app does implement a foreground service, and the problem seemed to be caused by calling Android.App.Service.StopForeground(true) when pausing playback (to allow the user to dismiss the notification).  After this call and subsequently re-promoting the service to the foreground, networking fails. We've taken out the StopForeground call for now.

Ian @ un4seen

  • Administrator
  • Posts: 21211
Re: BASS for Android
« Reply #1464 on: 12 Oct '18 - 15:32 »
A BASS update is up in the first post, to fix support for STREAMPROC constants (eg. STREAMPROC_PUSH) on the arm64-v8a architecture.