jrfeng / snow

Android music player framework, compatible with MediaSession. Support custom music player (MediaPlayer, ExoPlayer), custom Notification, custom audio effect engine, only WiFi network, sound quality/dynamic URL, headset clicks, sleep timer, playback history, player state persistence.
MIT License
190 stars 45 forks source link

Need Clear Playlist #11

Closed webwayscript closed 4 years ago

webwayscript commented 4 years ago

If we add extra item inside playlist its not update when open app or setPlaylist. Its playing old play list only .. we need clear playlist before adding setPlaylist. We using like this from arraylist

 `   private Playlist createPlaylist() {
    return new Playlist.Builder()
            .appendAll(fmradiomodellist)
            .build();
}`
jrfeng commented 4 years ago

Edit Playlist:

Playlist is immutable. If you want edit playlist, the following methods of PlayerClient can be used:

Observe Playlist changed:

There are two options:

Example:

// Option 1: use PlayerViewModel
playerViewModel.getPlaylist().observe(lifecycleOwner, new Observer<Playlist>() {
        @Override
        public void onChanged(Playlist playlist/*fresh playlist*/) {
                // ...
        }
 });

// Option 2: add a Player.OnPlaylistChangeListener
mPlayerClient.addOnPlaylistChangeListener(this, new Player.OnPlaylistChangeListener() {
        @Override
        public void onPlaylistChanged(PlaylistManager playlistManager, int position) {
                // use PlaylistManager to get the fresh playlist
                playlistManager.getPlaylist(new PlaylistManager.Callback() {
                    @Override
                    public void onFinished(@NonNull Playlist playlist/*fresh playlist*/) {
                        // ...
                    }
                });
        }
});
webwayscript commented 4 years ago

No . we not talking about add or remove item inside playlist. this one is very interesting.

  1. I have 4 item in my api url.
  2. when open app json parsing from internet then add to arraylist called fmradiomodellist
  3. Then i add this arraylist using .appendAll(fmradiomodellist) inside createPlaylist
  4. On item click i call playerClient.setPlaylist(createPlaylist(), selectedPos,true);

Now all 4 item playing correctly. Now i add or remove item from json api .. ex now 5 items inside json when i close and reopen app now inside my listview i have 5 items . Bot on click only 4 item playing new item not updated.

after uninstall and reinstall app now only i get 5 items...

i think you need updateplalist() clearplaylist() or something. I dont know inside my listview i saw 5 items ..fmradiomodellist size also 5.. but playing only 4 .. If i removed item from json its not removed inside playlist if i call playerClient.setPlaylist.

i also try with.. not work

`.removeAll(fmradiomodellistok)
  .appendAll(fmradiomodellistok)
  .build();`
jrfeng commented 4 years ago

Playlist is immutable, if your json data modified, you need set a new playlist.

webwayscript commented 4 years ago

Ok how in My case?

jrfeng commented 4 years ago

It's up to you. If you want update playlist when json data changed, just use setPlaylist set a new playlist. If you don't want update playlist, just keep it.

webwayscript commented 4 years ago

Ok .. Now i understand ... lol it was my mistake Thank you . i need clear my SharedPreferences thank you

jrfeng commented 4 years ago

If you modify the json data, you should also update the Playlist. Example: when you add or remove item from json api, you should add or remove it from Playlist at the same time.

webwayscript commented 4 years ago

Yes bro thank you its fixed.