سؤال

I'm working on an app for a band, which consists of several different activities such as an agenda, news section, album section et cetera. Since it's for a band, I would like to play the band's songs in the background.

This isn't such a problem, but I would like to show a small music player on the bottom of all activities so users can always stop, skip, or replay a song if they want to. An example of this can be found in the apps of Mobile Roadie, for instance.

However I have no idea how to do this. My best guess is creating a music player class with its own layout, and including this at the bottom of each activity/layout. But since every activity starts in its own thread, I'm guessing this would reset the player for each activity.

So, how would I go about adding a common music player to all of my activities, where the state of the music player would be maintained?

For an example, download any of the music based apps of Mobile Roadie and you'll know what I mean.


I decided on using Fragments, but I'm not sure if I can use those in already existing activities. All the examples I found focus on completely new projects, and not already existing ones. So in short, can you create fragments and use them in already existing activities? (such as showing the music player on top of the existing agenda activity)

هل كانت مفيدة؟

المحلول

I suggest you doing it the following way. Since music playing state must be retained in all the activities, you have to use a service to achieve this. Also you need a control panel, which must exist separately from activities. The best method to do it is by using fragments. Create a fragment which connects to the service and provides an UI to control it, then add this fragment to all the activities where you need it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top