Author Topic: Android Error File Open  (Read 443 times)

Ano

  • Guest
Android Error File Open
« on: 22 Nov '22 - 14:56 »
Hello,

i have a Problem with the Bass for Android, Bass_Init returns true, but everytime i get the errorcode 2 when i use BASS_StreamCreateFile, but the File exists.
When i try to play the same file with the example projects it works. Permssion for reading the external is granted. I have copied the filepath the i have picked(Logcat-Output) in your app into my project, but allways it fails. I have try to create the stream in a thread too, same result. What can cause this?

Code: [Select]
        File file = new File(filename);
        if(file.exists())
        {
            Log.i(TAG, "FILE EXISTS");
            stream = BASS.BASS_StreamCreateFile(filename, 0, 0, BASS.BASS_SAMPLE_FLOAT);
            if(stream == 0)
            {
                Log.i(TAG, String.valueOf(BASS.BASS_ErrorGetCode()));
            }
            else
            {
                BASS.BASS_ChannelPlay(stream, false);
            }
        }
        else
        {
            Log.i(TAG, "FILE NOT EXISTS");
        }


Chris

  • Posts: 2132
Re: Android Error File Open
« Reply #1 on: 22 Nov '22 - 16:43 »
is the Filename inc the Path ?

Ano

  • Guest
Re: Android Error File Open
« Reply #2 on: 22 Nov '22 - 17:54 »
Yes, this is an example

/storage/7DC5-1BF8/Music/Some Folder/01~SomeTiltle~SomeArtist.mp3

The file exists, Permission is granted.

In the Examples when i pick a file via the Dialog it works, i had printed the full filename into Logcat, from logcat copied into my project, error code 2.



Ian @ un4seen

  • Administrator
  • Posts: 25060
Re: Android Error File Open
« Reply #3 on: 22 Nov '22 - 18:00 »
Error code 2 is BASS_ERROR_FILEOPEN, which means it was unable to open the file. That could be because the file doesn't exist or the app doesn't have permission to access it. If the exact same file/path is accessible with the BASS examples then I guess it's a permissions issue. Are you requesting the READ_EXTERNAL_STORAGE permission in your app's manifest and at runtime via requestPermissions, like in the examples? Also, what Android version are you targetting, ie. the targetSdkVersion setting?

Ano

  • Guest
Re: Android Error File Open
« Reply #4 on: 22 Nov '22 - 19:11 »
I use ActivityCompat.checkSelfPermission and ActivityCompat.requestPermissions, READ_EXTERNAL_STORAGE is PackageManager.PERMISSION_GRANTED when i get the result in onRequestPermissionsResult.

Min-API is 29
Target API is 32

Debugging-Hardware-Device-API is 29

Ano

  • Guest
Re: Android Error File Open
« Reply #5 on: 22 Nov '22 - 19:21 »
Sry cant edit, because not logged in.

I have tried with this config
Code: [Select]
android {
    compileSdk 32


    defaultConfig {
        applicationId "..........."
        minSdk 14
        targetSdk 22
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

This works.

Ian @ un4seen

  • Administrator
  • Posts: 25060
Re: Android Error File Open
« Reply #6 on: 23 Nov '22 - 16:39 »
It looks like you were running into Android's scoped storage restrictions when targetting the more recent Android version:

   https://developer.android.com/about/versions/11/privacy/storage

You can get around that by targetting an older Android version (like you have now), or getting a ParcelFileDescriptor for the file and passing that (instead of the filename) to BASS_StreamCreateFile, something like this:

Code: [Select]
ParcelFileDescriptor pfd = getContentResolver().openFileDescriptor(uri, "r");
stream = BASS.BASS_StreamCreateFile(pfd, 0, 0, 0);

Ano

  • Guest
Re: Android Error File Open
« Reply #7 on: 23 Nov '22 - 21:23 »
Yes, the scoped storage. After adding this Line in the Manifest
Code: [Select]
        android:requestLegacyExternalStorage="true"It works on Android 10 when targeting the newest API. Default this is false.

OK time to study the new storage system, because this flag is beeing ignored on Android 11 Devices.

Thank you for the help.  :)