Skip to content

Commit

Permalink
Use ContextCompat.getMainExecutor when calling MediaBrowser methods
Browse files Browse the repository at this point in the history
This allows the service to be switched to run in another process and the app still works the same as if it is running in the same process.

Issue: #100
PiperOrigin-RevId: 458460005
(cherry picked from commit c9abe70)
  • Loading branch information
marcbaechinger authored and rohitjoins committed Jul 1, 2022
1 parent 1ec7148 commit 23888c1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import android.widget.ArrayAdapter
import android.widget.ListView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.media3.common.MediaItem
import androidx.media3.session.LibraryResult
import androidx.media3.session.MediaBrowser
Expand Down Expand Up @@ -164,7 +165,7 @@ class MainActivity : AppCompatActivity() {
val root: MediaItem = result.value!!
pushPathStack(root)
},
MoreExecutors.directExecutor()
ContextCompat.getMainExecutor(this)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import android.widget.LinearLayout
import android.widget.ListView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.media3.common.MediaItem
import androidx.media3.common.Player
import androidx.media3.session.MediaBrowser
Expand Down Expand Up @@ -150,7 +151,7 @@ class PlayableFolderActivity : AppCompatActivity() {
val result = mediaItemFuture.get()!!
title.text = result.value!!.mediaMetadata.title
},
MoreExecutors.directExecutor()
ContextCompat.getMainExecutor(this)
)
childrenFuture.addListener(
{
Expand All @@ -161,7 +162,7 @@ class PlayableFolderActivity : AppCompatActivity() {
subItemMediaList.addAll(children)
mediaListAdapter.notifyDataSetChanged()
},
MoreExecutors.directExecutor()
ContextCompat.getMainExecutor(this)
)
}

Expand Down

0 comments on commit 23888c1

Please sign in to comment.