Giter Site home page Giter Site logo

Comments (4)

marcbaechinger avatar marcbaechinger commented on July 20, 2024

You start the MediaSessionService by building a MediaController that then binds to the service.

The documentation section about the Service lifecycle explains how to stop the service.

from media.

DolaKrishnan08 avatar DolaKrishnan08 commented on July 20, 2024

Hello @marcbaechinger

  1. In My App I'm not using MediaController so I think this won't bind to the Service.
  2. As Document Suggested I'm clearing all instance when onDestroy is Triggered
fun stopService() {
            mediaSession.run {
                player.stop()
                player.release()
                release()
            }
            stopSelf()
    }
    override fun onDestroy() {
        stopForeGround()
        hideNotification()
        super.onDestroy()
    }
    
    private fun stopForeGround() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            stopForeground(STOP_FOREGROUND_REMOVE)
        } else {
            stopForeground(true)
        }
    }
    fun hideNotification() {
        playerNotificationManager?.setPlayer(null)
        playerNotificationManager= null
    }

from media.

marcbaechinger avatar marcbaechinger commented on July 20, 2024

The intended use of MediaSessionService is to be started with a controller and to use the controller to control playback. If based on your experience you choose to do your own thing this is fine, but I don't think we can extensively support you with this endeavor I'm afraid.

I'd recommend using the MediaSessionService with a controller. But surely, that decisions is yours.

The MediaSessionService implementation aims to make things easier for users that don't want to build their own service and hence don't need to read through the extensive foreground service documentation. Users that want to/have to read this documentation find that stopSelf is a no-op in the case the service is still running in the foreground. So you'd have to call stopForeGround() before calling stopSelf()?

When not requiring a controller, I think I'd just create my own Service implementation and refrain from using MediaSessionService. This may be easier than bending MediaSessionService your way. Certainly we are convinced that using MediaSessionService in the intended way is the easiest approach and benefits developers that want to build a media app.

from media.

DolaKrishnan08 avatar DolaKrishnan08 commented on July 20, 2024

Hello @marcbaechinger
I Got Your Point It's Best to use MediaController when the service is MediaSessionService may be I will looks in to this, But Once MediaSessionService is Started as Normal Service with startForeGroundService(ServiceName) In OnStartCommand I am pushing PlayerNotificationManager with startForeground(NotificationConstants.NOTIFICATION_ID, notification)

Once User is Closing the App From OnDestroy I'm calling StopService(Service) where I Clear All Instance and stopForegound like private fun stopForeGround() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
stopForeground(STOP_FOREGROUND_REMOVE)
} else {
stopForeground(true)
}
}

After This I'm calling **stopSelf()** Notification was cleared But Service is Not Destroying Any Suggestions on This Would Help me lot, Thank You!!

from media.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.