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

How to have a good storage structure for multiple playlists? #70

Closed
vsay01 opened this issue Jan 20, 2016 · 9 comments
Closed

How to have a good storage structure for multiple playlists? #70

vsay01 opened this issue Jan 20, 2016 · 9 comments
Labels

Comments

@vsay01
Copy link

vsay01 commented Jan 20, 2016

Hi,
I notice there is a static variable PlayListManager that will be used in the AudioPlayerActivity.java

Each time this method invoked in the AudioPlayerActivity
playlistManagerAudioActivity.play(selectedIndex, false);

The AudioService.class will be started.

I followed the demo and it works fine for one playlist.

However, if I have multiple playlist then should I :

  • have different AudioPlayerActivity for each playlist?
  • continue using the static variable in App.java which is the playListManager for all playlists?
    One issue that I met using static variable in App.java which is the playListManager for all playlists was that when I play a song from list 1, then switch back select another song from list 2 when I click on the foreground notification it will play a song that I chose from list 1 and not the latest one.

What do you think?
Thank

@brianwernick
Copy link
Owner

You should continue using a static (singleton) implementation for the PlaylistManager. When switching a playlist you will need to

  1. Update the actual playlist storage in the PlaylistManager (setParameters(...))
  2. Update the playlist id (setPlaylistId(...))
  3. Set the index of the item to play (setCurrentItem(...))
  4. Start playback (play(...))

@vsay01
Copy link
Author

vsay01 commented Jan 20, 2016

As I mentioned I tried to use static implementation:
Here is the current issue I have Though I will recheck it again.
Scenario:

  • I click on a song called A from list 1 --> AudioPlayerAcitivty.java started and play song A
  • go back and choose a song called A" from list 2 --> AudioPlayerActivity.java started ( go to onResume - since already created before) and play song A"
  • go back to playlist or home screen
  • select the foreground notification

Expected: open AudioPlayerActivity and play song A" list 2

Actual: open AudioPlayerActivity and play song A list 1

I tried to track down the value static playlistManager in the App.java, it changed when A" from list 2 clicked but the problem is that when A' from list 1 clicked and play the service started already and when A" from list 2 clicked the player not started again since it will fire the onResume() callback of the AudioPlayerActivity.java.

Let me know if you need clarification...
Thank

@brianwernick
Copy link
Owner

What is your implementation of protected PendingIntent getNotificationClickPendingIntent() in the PlaylistService?

@vsay01
Copy link
Author

vsay01 commented Jan 20, 2016

Here it is
@OverRide
protected PendingIntent getNotificationClickPendingIntent() {
Log.e("AuoSeice geNotiClkP= ", getMediaPlaylistManager().getPlayListId()+"");
Intent intent = new Intent(getApplicationContext(), AudioPlayerActivity.class);
intent.putExtra(AudioPlayerActivity.EXTRA_INDEX, getMediaPlaylistManager().getCurrentIndex());
intent.putExtra(AudioPlayerActivity.EXTRA_PLAYLISTID, (int)getMediaPlaylistManager().getPlayListId());
return PendingIntent.getActivity(getApplicationContext(), FOREGROUND_REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}

@brianwernick
Copy link
Owner

OK, currently the pendingIntent is only updated when the service is set as a Foreground service. I'll update it shortly to correctly update when the notification is updated.

@vsay01
Copy link
Author

vsay01 commented Jan 20, 2016

Great thank,
I suppose after that update, the singleton implementation for multi playlist should be fine.

@brianwernick
Copy link
Owner

Yep. I usually have a different setup so I haven't hit this issue before. I should be releasing 2.5.2 in a few minutes

@brianwernick
Copy link
Owner

2.5.2 has been released

@vsay01
Copy link
Author

vsay01 commented Jan 20, 2016

Confirm fixed.. Thank

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants