Strange behavior of the MediaControllerCompat onPlayFromMediaId () method

I work with a service that extends MediaBrowserServiceCompat , and also has MediaSessionCompat.Callback() with its overridden methods, including onPlayFromMediaId() .

Inside the fragment that has a recyclerview when the recyclerview element is clicked, the following code is called. As you can see from the image, it is clear that mediaId , as well as songBundle have values ​​and are passed to the onPlayFromMediaId() method.

enter image description here

It is strange that inside the Service class, where the playFromMediaId() method is overridden, it receives only the value for the string variable mediaId , and the songBundle magically becomes empty. (Note: the key used to place and receive the argument is also the same. The original songsVO is a POJO that implements the Parcelable interface.)

enter image description here

In addition to this other interesting thing that I noticed, I return to the snippet called onPlayFromMediaId() later after executing it, and check the values ​​of each variable except mediaId every other variable becomes zero.

enter image description here enter image description here

RecyclerAdapter Class

  class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ViewHolder> { @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View itemView = inflater.inflate(R.layout.layout_song_item, parent, false); return new ViewHolder(itemView); } @Override public void onBindViewHolder(ViewHolder holder, final int position) { holder.cardView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // songPicked(position); songsVO=songsVOArrayList.get(position); mediaId=songsVO.getFilePath(); songBundle=new Bundle(); songBundle.putParcelable("song",songsVO); // MediaControllerCompat.getMediaController(getActivity()).getTransportControls().playFromMediaId(mediaId, songBundle); MediaControllerCompat.getMediaController(getActivity()).getTransportControls().play(); currentState = STATE_PLAYING; holder.imageView.setImageBitmap(songsVOArrayList.get(position).getAlbumArt()); holder.title.setText(songsVOArrayList.get(position).getTitle()); holder.artist.setText(songsVOArrayList.get(position).getArtist()); holder.duration.setText(songsVOArrayList.get(position).getDuration()); } @Override public int getItemCount() { return songsVOArrayList.size(); } class ViewHolder extends RecyclerView.ViewHolder { CardView cardView; ImageView imageView; TextView title, artist, duration; public ViewHolder(View itemView) { super(itemView); cardView = (CardView) itemView.findViewById(R.id.layout_song_item); imageView = (ImageView) itemView.findViewById(R.id.img_albumart); title = (TextView) itemView.findViewById(R.id.txt_title); artist = (TextView) itemView.findViewById(R.id.txt_artist); duration = (TextView) itemView.findViewById(R.id.txt_duration); } } } 

TL; onPlayFromMediaId(String, Bundle) only passes the String variable, while the bundle is empty.

Link- This tutorial

+6
android android-service android-mediaplayer
source share

No one has answered this question yet.

See related questions:

3
RecyclerView: how to catch onClick on ImageView?
2
Scrolling lags after applying font in Recycler view elements
one
Android flipper works on emulator, but not on device
one
RecyclerView itemView childView getHeight () is always 0
one
Weird OutOfMemoryError when loading view pager
0
ListFragment Error
0
How to implement serial with my custom class containing Hashmap and SparseArray?
0
Saving ToggleButton state in ListView using SharedPreferences
0
Cannot catch Child View touch event of Sticky Header (RecyclerView) by eowise
0
RecyclerView with multiple data types and data source

All Articles