brianwernick / ExoMedia

An Android ExoPlayer wrapper to simplify Audio and Video implementations
Apache License 2.0
2.14k stars 379 forks source link

How to provide easy access to now playing playlist? #74

Closed vsay01 closed 8 years ago

vsay01 commented 8 years ago

Hi, From the demo, we can play the audio playlist in the AudioPlayerActivity and AudioService handle all the audio service took place when play music. Thus, currently with the demo if I have more than one playlist then I wont be able to go to now playing playlist.

I have three different playlist possible four, I looked at the google play music in which the now playing bar appear at the bottom of the play list activity. And when user tap or swap it up then the audio player appear.

Which are the possible ways I can create that now playing behavior, in other word, it appears as a now playing bar when user back to playlist and when user tap or swipe it up audio player like the AudioPlayerActivity appear?

What I am thinking is using the fragment by converting the AudioPlayerActivity to AudioPlayerFragment and attach it with the three playlist.

what do you think? Thank

brianwernick commented 8 years ago

Correct. You should be using a Fragment for the audio player if you want functionality like Google Play Music. However, the fragment shouldn't have any knowledge of the different playlists, that should be handled elsewhere; and is only in the Activity in the demo because it's a simple way to show the interaction.

vsay01 commented 8 years ago

@brianwernick Thank; When you mentioned: "However, the fragment shouldn't have any knowledge of the different playlists, that should be handled elsewhere" Could you elaborate it?

brianwernick commented 8 years ago

The Audio Fragment should only be used to display the current playback information (title, image, state, etc.) leaving the actual playback to the PlaylistService and the control of playback to the PlaylistManager (which is usually called from the Audio Fragment for seek, next, etc.). This leaves the actual loading, or swapping, of the playlist to a separate object. Usually in my apps I will pass an argument to the Audio Activity (Fragment in this case) that will uniquely indicate the playlist in a database, then have the Activity kick off an async task (or Loader) that will handle the retrieval, update, and initial playback for that playlist.

Using Google Play Music as an example; When you click to play a "Station" you aren't presented with a list of media items, therefore they are kicking off a background task to load a list of items to play (they may actually be using client-server communications, but lets assume they aren't). Alternatively, even when you select a playlist that you have created, you will view a list of items in that playlist in a separate Fragment (or in the Activity itself). Then when you click on one to play the separate Audio Fragment is created which only displays the information as described above.

vsay01 commented 8 years ago

@brianwernick Thank for the clarification... For my case I have three static playlist (presented in three different fragment) in each fragment I create a static ArrayList to hold all the songs of the playlist.....

Then in the AudioPlayerActivity I tested if the playlist sent through intent let's say 1 for static playlist 1 i will set parameter of the playlistManager to the static arraylist of the playlist 1 fragment.

I think if I want to move the AudioPlayerActivity to fragment i need to rethink of how well i can access to each playlist rather then access to static variable of each playlist.

Local database with loader might be an option.

vsay01 commented 8 years ago

@brianwernick If I change the AudioPalyerActivity to Fragment then Should I keep the static variable arralylist of the audios in each static playlist or are there any better way for me to access to each list of the playlist?

I want to create playlist as well so in that case what the best way to keep all data well structures so that the fragment can be easily created when play music?

Does the fragment is supposed to be globally for every part of the application? let say i moved from playlist to search activity to other activity then fragment supposed to be appeared stick bottom of the screen.

brianwernick commented 8 years ago

In your case, I would create a utility class that would contain the multiple static playlists (Only if they have to be static). Then when you reach the points where you need to load a playlist (or change playlists) have a task perform the loading from the utility. This will keep the implementation of the playlist away from the Fragment and allow you to re-use the fragment throughout the app.