Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

android.media.AudioFocusRequest.Builder crash #195

Open
chris-praxis opened this issue Jul 6, 2022 · 3 comments
Open

android.media.AudioFocusRequest.Builder crash #195

chris-praxis opened this issue Jul 6, 2022 · 3 comments

Comments

@chris-praxis
Copy link

Crash happens on Android 7 where this API is not available. Code appears to be missing a if (android.os.Build.VERSION.SDK_INT >= 26) check.

@djmaze
Copy link

djmaze commented Jul 29, 2022

AFAICS, that check just needs to to be removed. The rest of the code seems to support Android < 8 correctly.

@chris-praxis
Copy link
Author

I'm saying a version check needs to be added, and you're saying some check needs to be removed? I don't follow. Here's my change, simply wrapping some audio focus code in a version check...

node_modules/nativescript-audio/android/player.js
38,46c38,48
< const playbackAttributes = new android.media.AudioAttributes.Builder()
< .setUsage(options.usage)
< .setContentType(options.contentType)
< .build();
< this._audioFocusRequest = new android.media.AudioFocusRequest.Builder(options.durationHint)
< .setAudioAttributes(playbackAttributes)
< .setAcceptsDelayedFocusGain(true)
< .setOnAudioFocusChangeListener(this._mOnAudioFocusChangeListener)
< .build();

    if (android.os.Build.VERSION.SDK_INT >= 26) {
        const playbackAttributes = new android.media.AudioAttributes.Builder()
            .setUsage(options.usage)
            .setContentType(options.contentType)
            .build();
        this._audioFocusRequest = new android.media.AudioFocusRequest.Builder(options.durationHint)
            .setAudioAttributes(playbackAttributes)
            .setAcceptsDelayedFocusGain(true)
            .setOnAudioFocusChangeListener(this._mOnAudioFocusChangeListener)
            .build();
    }

@djmaze
Copy link

djmaze commented Aug 31, 2022

Ohh.. looking at it again, I was wrong I guess. But a few lines earlier, there is the following: https://github.com/nstudio/nativescript-audio/blob/master/src/android/player.ts#L40-L42

So the additional check should not be necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants