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

when invoke service.startforegorund method i got error #518

Open
BatuhanAkar opened this issue Apr 5, 2023 · 0 comments
Open

when invoke service.startforegorund method i got error #518

BatuhanAkar opened this issue Apr 5, 2023 · 0 comments

Comments

@BatuhanAkar
Copy link

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {

            int audioFocusRequestResult = audioManager.requestAudioFocus(audioFocusRequest) ;

                if (audioFocusRequestResult == AudioManager.AUDIOFOCUS_REQUEST_GRANTED){


                    getApplicationContext().startService(new Intent(getApplicationContext(),MediaPlaybackService.class)) ;
                    mediaSession.setActive(true) ;

                    mediaPlayer.play();
                    registerReceiver(receiver , intentFilter) ;
                   //  service.startForeground(101 , notification);

                    **service.startForeground(101 , new android.app.Notification());**


                }
        }

i can't see any initialize of the service here

https://developer.android.com/guide/topics/media-apps/audio-app/mediasession-callbacks

Ekran görüntüsü 2023-04-05 222954

---error---

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.service.media.MediaBrowserService.startForeground(int, android.app.Notification)' on a null object reference
at com.batuscode.mediabrowserservice.MediaPlaybackService$SessionCallBack.onPlay(MediaPlaybackService.java:170)
at android.support.v4.media.session.MediaSessionCompat$Callback$MediaSessionCallbackApi21.onPlay(MediaSessionCompat.java:1621)
at android.media.session.MediaSession$CallbackMessageHandler.handleMessage(MediaSession.java:1607)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7839)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

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

1 participant