Skip to content

feat(audio): migrate AudioService to MediaLibraryService#3513

Open
AhmedGamal92 wants to merge 2 commits intoquran:mainfrom
AhmedGamal92:migrate_AudioService_to_MediaLibraryService
Open

feat(audio): migrate AudioService to MediaLibraryService#3513
AhmedGamal92 wants to merge 2 commits intoquran:mainfrom
AhmedGamal92:migrate_AudioService_to_MediaLibraryService

Conversation

@AhmedGamal92
Copy link

Migrates the AudioService from the legacy Service to androidx.media3.session.MediaLibraryService.

This change introduces MediaLibrarySession to handle media playback, replacing parts of the older MediaSessionCompat implementation. A new QuranServiceCallback class is also added for future integration with media controllers like Android Auto.

The motivation behind this migration is to build on top of it to enable a better android auto support (check the issue #1086), the end goal is to use the same audio service to sync the player items (surahs) and playback state with android auto, similar to other media playback apps.

Migrates the `AudioService` from the legacy `Service` to `androidx.media3.session.MediaLibraryService`.

This change introduces `MediaLibrarySession` to handle media playback, replacing parts of the older `MediaSessionCompat` implementation. A new `QuranServiceCallback` class is also added for future integration with media controllers like Android Auto.
@AhmedGamal92
Copy link
Author

@ahmedre
SA
I'm not sure what is the usual practice you follow when such migration is needed, two questions I have:

  • While I did test the audio service functionality on couple of devices and things are working the same, how do we ensure proper QA to avoid any side effects ?
  • As this PR by itself doesn't introduce extra functionalities, I see it better to merge and test that migration individually before introducing the later changes specific to Android Auto, as also this one affects the main app, wdyt ?

@ahmedre
Copy link
Contributor

ahmedre commented Feb 5, 2026

wa3laikum alsalam - jazakumAllah khairan for the pr!
will read this during the weekend in more detail in sha' Allah. to answer your question though, agree with the second point. unfortunately for the first point, don't have any tests or anything and it's a bit difficult to test some of this stuff (integration with the service, etc) so don't have any great ideas there.

@github-actions
Copy link

github-actions bot commented Feb 5, 2026

OLD: app-madani-debug.apk (signature: V1, V2)
NEW: app-madani-debug.apk (signature: V1, V2)

          │            compressed             │          uncompressed          
          ├───────────┬───────────┬───────────┼───────────┬───────────┬────────
 APK      │ old       │ new       │ diff      │ old       │ new       │ diff   
──────────┼───────────┼───────────┼───────────┼───────────┼───────────┼────────
      dex │  20.1 MiB │  20.1 MiB │  +2.4 KiB │  50.6 MiB │  50.6 MiB │ +6 KiB 
     arsc │   2.1 MiB │   2.1 MiB │       0 B │   2.1 MiB │   2.1 MiB │    0 B 
 manifest │   5.6 KiB │   5.6 KiB │       0 B │  26.2 KiB │  26.2 KiB │    0 B 
      res │   1.8 MiB │   1.8 MiB │       0 B │     2 MiB │     2 MiB │    0 B 
   native │  85.4 KiB │ 112.7 KiB │ +27.3 KiB │  36.5 KiB │  36.5 KiB │    0 B 
    asset │   1.6 MiB │   1.6 MiB │       0 B │   3.8 MiB │   3.8 MiB │    0 B 
    other │ 200.1 KiB │ 200.1 KiB │     +13 B │ 501.5 KiB │ 501.5 KiB │    0 B 
──────────┼───────────┼───────────┼───────────┼───────────┼───────────┼────────
    total │  25.9 MiB │  25.9 MiB │ +29.6 KiB │    59 MiB │  59.1 MiB │ +6 KiB 

@ahmedre
Copy link
Contributor

ahmedre commented Feb 8, 2026

looks good to me, جزاكم الله خيراً

minor points:

  1. as you suggested, fixing the potential null return from onGetSession
  2. we override onStartCommand and return START_NOT_STICKY, when it seems like the underlying MediaSessionService always returns START_STICKY.

can you try to test media buttons to make sure they still work (if you have headphones that can pause/resume playback etc)?

@AhmedGamal92
Copy link
Author

looks good to me, جزاكم الله خيراً

minor points:

  1. as you suggested, fixing the potential null return from onGetSession
  2. we override onStartCommand and return START_NOT_STICKY, when it seems like the underlying MediaSessionService always returns START_STICKY.

can you try to test media buttons to make sure they still work (if you have headphones that can pause/resume playback etc)?

@ahmedre pushed a commit getting rid of the serviceHandler as discussed earlier, please check now

@ahmedre
Copy link
Contributor

ahmedre commented Feb 12, 2026

wa3laikum alsalam wa ra7matullah,
jazakumAllah khairan!
2 things:

  1. I think we'll be double handling media buttons this way (via MediaButtonReceiver.handleIntent), and I think MediaLibraryService already handles this for us.
  2. secondly, in our relaxResources and makeOrResetExoPlayer, we never re-bind the session to the new player using mediaLibrarySession?.setPlayer(.

@github-actions
Copy link

OLD: app-madani-debug.apk (signature: V1, V2)
NEW: app-madani-debug.apk (signature: V1, V2)

          │            compressed             │           uncompressed           
          ├───────────┬───────────┬───────────┼───────────┬───────────┬──────────
 APK      │ old       │ new       │ diff      │ old       │ new       │ diff     
──────────┼───────────┼───────────┼───────────┼───────────┼───────────┼──────────
      dex │  20.1 MiB │  20.1 MiB │  +2.2 KiB │  50.6 MiB │  50.6 MiB │ +4.7 KiB 
     arsc │   2.1 MiB │   2.1 MiB │       0 B │   2.1 MiB │   2.1 MiB │      0 B 
 manifest │   5.6 KiB │   5.6 KiB │       0 B │  26.2 KiB │  26.2 KiB │      0 B 
      res │   1.8 MiB │   1.8 MiB │       0 B │     2 MiB │     2 MiB │      0 B 
   native │  82.6 KiB │ 110.2 KiB │ +27.6 KiB │  36.5 KiB │  36.5 KiB │      0 B 
    asset │   1.6 MiB │   1.6 MiB │       0 B │   3.8 MiB │   3.8 MiB │      0 B 
    other │ 200.1 KiB │ 200.1 KiB │     -10 B │ 501.5 KiB │ 501.5 KiB │      0 B 
──────────┼───────────┼───────────┼───────────┼───────────┼───────────┼──────────
    total │  25.9 MiB │  25.9 MiB │ +29.8 KiB │  59.1 MiB │  59.1 MiB │ +4.7 KiB 

@github-actions
Copy link

Upgraded Dependencies
androidx.activity:activity:1.12.3, (changed from 1.12.4)
androidx.activity:activity-compose:1.12.3, (changed from 1.12.4)
androidx.activity:activity-ktx:1.12.3, (changed from 1.12.4)

@AhmedGamal92
Copy link
Author

wa3laikum alsalam wa ra7matullah, jazakumAllah khairan! 2 things:

  1. I think we'll be double handling media buttons this way (via MediaButtonReceiver.handleIntent), and I think MediaLibraryService already handles this for us.
  2. secondly, in our relaxResources and makeOrResetExoPlayer, we never re-bind the session to the new player using mediaLibrarySession?.setPlayer(.

True, good catch, we should cleanup the mediaSessionCompat, the MediaLibraryService should handle that for us, updating the PR soon.

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

Successfully merging this pull request may close these issues.

2 participants